Arduino: Where is the Serial.begin symbol defined? - arduino

I am working on linux with .deb package of arduino for debian, so I can find HardwareSerial under:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h
but I am interested in locate the Serial definition and/or implementatio, this should be more than a typedef or using because in HardwareSerial class begin is not static and you can write: Serial.begin(9600); for example.
So some body know where is Mr Serial?

Serial is an object of HardwareSerial.

Related

Can't use an installed library in Arduino IDE

I have already installed a library for oled display. Then I include this in my code with: #include <Adafruit_SSD1306.h>, but then I get an error:
display_test:1:30: error: Adafruit_SSD1306.h: No such file or directory
compilation terminated.
exit status 1
Adafruit_SSD1306.h: No such file or directory
This is the path to Adafruit_SSD1306.h: C:\Users\filip\OneDrive\Dokumente\Arduino\libraries\Adafruit_SSD1306
Full code:
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
void setup()
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Serial.begin(9600);
}
void loop()
{
display.clearDisplay();
display.setTextColor(WHITE);
display.setCursor(0,15);
display.setTextSize(2);
display.print((char)247);
display.print("C");
display.display();
}
It looks like the Arduino IDE is looking for the library in the wrong folder. You can try importing it manually and see what happens:
#include "C:\Users\filip\OneDrive\Dokumente\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.h"
#include "C:\Users\filip\OneDrive\Dokumente\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp"
When that works, try removing the library from that folder and reinstall it using the Library Manager. You can open the Library Manager by pressing ctrl + shift + i. Then just set type and topic to all and enter Adafruit_SSD1306 in the search bar. It will search and find the library for you, then just install.
Also, the library might be installed but not be compatible with your board (for example because it uses chip specific internal timers). So, try to find out if the library is suitable for your board.

Getting an syntax error by using RasPiArduino for Raspberry Pi

I am using an Raspberry Pi Zero with an L298n motor driver to control two motors. I was testing the motors using a Python script. That worked fine.
Now I wanted to use the Arduino software to program the motors. I was following this tutorial on how to archive that: https://www.youtube.com/watch?v=lZvhtfUlY8Y
Then I coded this into the Arduino software (v. 1.8.5)
void setup() {
// put your setup code here, to run once:
Console.println("Setup Einstellungen");
pinMode(17, OUTPUT);
delay(500);
Console.println("Setup Einstellungen Ende");
}
void loop() {
Console.println("Rechts Vorwärts");
digitalWrite(17, HIGH);
delay(1000);
digitalWrite(17, LOW);
delay(5000);
}
I compiled the file using "Export compiled Binary". I uploaded it on the Raspberry using FileZilla and tried to run it via SSH.
When I tried to run it with:
(sudo) sketch_feb28.ino.bplus.bin
I got the following error:
: -bash: syntax error near unexpected token `sketch_feb28.ino.bplus.bin'
Running file sketch_feb28.ino.bplus.bin
sketch_feb28a.ino.bplus.bin: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SY SV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2 .0, BuildID[sha1]=a0260345a3700dca64c63fde8a10959214ce9b85, not stripped
I cannot solve this issue alone.
I'm still not sure, where the syntax error comes from.
Run the file with:
./sketch_feb28.ino.bplus.bin
This is the syntax for running a binary, that is not in PATH. Since the file is a valid executable, the error message should vanish.

Intel Pin 3.0 does not recognize MPX instructions?

I have the latest version of Intel Pin 3.0 version 76887.
I have an MPX-enabled toy example:
#include <stdio.h>
int g[10];
int main(int argc, char **argv) {
int x = g[11];
printf("%d\n", x);
return 0;
}
When compiled with gcc + MPX, I see MPX instructions in the disassembly via objdump, and the example correctly writes me a bounds violation:
Saw a #BR! status 0 at 0x401798
Now I'd like to count the total number of specific MPX instructions using Intel Pin, e.g., BNDLDX and BNDMK.
My first attempt was using the shipped tool source/tools/SimpleExamples/trace.cpp. This tool showed me NOPs at places of MPX instructions.
In my second attempt, I wrote my own tool with the following snippet:
xed_iclass_enum_t iclass = (xed_iclass_enum_t)INS_Opcode(ins);
if (iclass == XED_ICLASS_BNDMK)
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)countBndmk, IARG_END);
This doesn't work, countBndmk is never called. I double-checked my code with other instruction iclasses, and they worked. So clearly there is a problem of Pin (or XED?) not recognizing MPX instructions.
Browsing the docs, I noticed an interesting knob
KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")
This knob seems to enable MPX decoding and is 0 by default, and I don't know how to enable it per command-line or in my tool. I found no other references to this problem in code or internet.
I know I could use Intel SDE to dump the debug trace including MPX instructions. I wonder if there is a way to enable MPX in Intel Pin. Or the only solution is to decode opcodes myself?
Maybe a little bit late to answer, but it seems that you have just to pass the option to PIN.
A little bit of background:
On the Intel manual there's this line (nothing to do with MPX, but it gives a clue):
Add the knob support_jit_api to the Pin command line as Pin tool option:
<Pin executable> <pin options> -t <Pin tool> -support_jit_api <Other Pin tool options> -- <Test application> <Test application options>
It happens there's an existing KNOB for this option:
KNOB<BOOL> LEVEL_PINCLIENT::KnobJitApi ( KNOB_MODE_WRITEONCE ,
"pintool:sym" ,
"support_jit_api" ,
"0" ,
"Enables the Jitted Functions Support"
)
As the MPX knob is defined as:
KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")
I guess you just have to pass the option to PIN:
<Pin executable> <pin options> -t <Pin tool> -xed_mpx_mode <Other Pin tool options> -- <Test application> <Test application options>
It seems that those KNOBs are hardcoded onto PIN / PinTools.

Running an Arduino program in NetBeans 7.3

I am using Arduino and NetBeans in my project. My final work is to switch from Arduino program to Java. I managed to install an Arduino-NetBeans plugin as described in Arduino - NetBeans Plugin detail
My Arduino program includes
Serial.begin(9600); /////// Serial.print();
I get an error saying that "Unable to resolve identifier Serial". How can I solve this?
this is what you have to add to your source file:
#include <Arduino.h>
// imports the Serial class to allow log output
extern HardwareSerial Serial;
then it will work.
As answered by cgo you can add extern HardwareSerial Serial;
Or into your Project Settings, go to BUILD > C++ COMPILER > PREPROCESSOR DEFINITIONS and add: __AVR_ATmega328P__ (if you are working with Arduino UNO)
The message "unable to resolve identifier Serial" means that the compiler is searching for the variable Serial, but cannot find its declaration. You should check if you include all header files properly. I don't know the NetBeans plugin, but I guess the Serial-structure/class is initialised there.
If that is not helping, you should check the compiler otions and set them to default, as described on the project-site.

Processing to Arduino "IllegalAccessError"

I hope this exact issue was not addressed already. I did search for a while.
So I'm using the Arduino library for Processing, testing it by simply having it blink an LED that I have connected to my Arduino UNO. I'm following this tutorial, but am having a problem a little different than the ones covered on that tutorial page. Here's my Processing code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
void setup()
{
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600); //error here
arduino.pinMode(ledPin, Arduino.OUTPUT);
}
void draw()
{
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}
Here's my error:
IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Exception in thread "Animation Thread" java.lang.IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
at cc.arduino.Arduino$SerialProxy.<init>(Arduino.java:119)
at cc.arduino.Arduino.<init>(Arduino.java:168)
at sketch_130206a.setup(sketch_130206a.java:29)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:680)
Since my error apparently has to do with access permissions, I tried doing what it says at the tutorial page I was following by going to /var/lock folder, but the /lock folder doesn't exist! I'm using a Mac 10.8.2. I searched around and found this thread (arduino dot cc/forum/index.php?topic=135164.0) and decided to try "sudo mkdir -p /var/lock" and "sudo chmod 777 /var/lock" in terminal, but it didn't change the error I have in Processing, even after restarting it. I also tried opening the Arduino app and uploading the StandardFirmata sketch as mentioned at the ProcessngxArduino library download page (playground.arduino dot cc/interfacing/processing) while trying to run the processing sketch, but same error. The fact that I'm using the Arduino UNO instead of the Duemilanove shouldn't be the issue as the UNO is apparently just an updated version of it. Any ideas what I could try to do next?
UPDATE: Okay so the highlighted error in my code is what opens the serial port I'm using at whatever rate (57600 bits/sec in this case I think). So I think the problem lies in this particular step in the instructions at the adrunio x processing info page mentioned earlier(playground dot arduino dot cc/interfacing/processing), step 3: "Configure Processing for serial: processing dot org/reference/libraries/serial/"... the link goes to processing's 'serial' reference page. I'm confused about what is meant by "configure"? How exactly do I figure out my "correct serial port"? I went through the rest of the instructions and the examples on the serial reference page, and still have no idea what I'm looking for.
UPDATE #2: My serial port for the arduino is "/dev/tty.usbmodem1411". I am still confused about how to plug this in to my code in Processing though. The things I just learned in these last 2 updates might be irrelevant to my error, I'm still unsure.
The problem was that I was using the beta version of Processing (2.0). Use the latest stable version (1.5.1) and it should work.

Resources