ESP32 serial connection to raspberry pi is "laggy" - arduino

I am using a ESP32 to write data to other devices. This works quite well, but when I send data to a Raspi I get a strange delay and wrong chars. Sometime the Pi seems to receive the correct data buts its totally random and takes forever.
Sending (ESP32):
#include <Arduino.h>
#define RXD2 16
#define TXD2 17
void setup() {
Serial.begin(9600);
Serial.println("Initialize");
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
Serial2.println("Sending data to you!");
Serial.println("Data send.");
delay(222);
}
Received data on Pi via sudo screen /dev/ttyS0 9600:

I found the issue. I did used a 5V 1A power supply for the RPi, which supplied not enough power. I am using a 3A now which runs perfecly flawless.

connect Arduino to the usb of the raspberry pi and try sudo screen dev/ubs(in which the arduino is connected) 9600 or try installing minicom and use "minicom -D /dev/ttyso -b 9600".

Related

What is default baudrate of serial communication of Octave Arduino Toolkit and how can i configure?

I tried Octave Arduino Toolkit and tried following command.
>> pkg load arduino
>> arduinosetup
Running "C:\Program Files (x86)\Arduino\arduino.exe" "C:\Users\XXXXXX\AppData\Local\Temp\oct-aiBvJS\octave\octave.in
o"
ans = 1
>> dev = arduino
dev =
arduino object with fields of:
port = \\.\COM4
board = uno
libraries = {
i2c
spi
servo
shiftregister
}
availablepins = {
d0 - d13
a0 - a5
}
>> val = readVoltage(dev,"A0")
val = 1.9746
So i think it is working correctly. But i do not know
Q1. What is default buadrate of COM4
Q2. How can i change the baudrate
Does any body know the answer for Q1 and Q2?
=========
I found OCTAVE_COMMS_PORT.begin (9600) in LiberaryBase.cpp that seems to configure baudrate. So i changed 9600 to other value.
Compile and write successed but arduino octave does not work correctly.
The error message on Octave is
>> dev = arduino("COM4")
error: __initArduino__: failed valid response err=2 - Malformed packet header
error: called from
__initArduino__ at line 34 column 8
arduino at line 94 column 16
You set the baudrate for the Arduino uno to use in your code, generally the setup block.
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
There's many supported rates and other options (https://www.arduino.cc/en/Serial.Begin), but unlikely you'll need more than the above line.

XBee Pro S3B/XSC problems using UART with microcontroller (AT90CAN64)

I have two Pro XBee Pro S3B, one is connected to my computer through USB, meanwhile the other is connected to a microcontroller AT90CAN64.
Here are the settings for each XBee, which I configured using XCTU:
- A (coordinator)
CE: Indirect Msg Coordinator [1]
ID: 71FF
SH: 13A200
SL: 418CCABF
DH: 13A200
DL: 418CCAB4
- B (router)
CE: Standard Router [0]
ID: 71FF
SH: 13A200
SL: 418CCAB4
DL: 418CCABF
I have both in Transparent Mode.
If I connect both A and B in my computer, if I use the XCTU terminal, I am able to exchange messages between them.
My main issue is the following: after I turn on the AT90CAN64, if I connect DIN/DOUT (XBee) to TX/RX (AT90CAN64), load the XCTU and try to exchange messages, I am not successful. However, if I do not connect TX/RX - DIN/DOUT, wait some time, then I connect TX/RX - DIN/DOUT, and then load XCTU, I am able to exchange messages.
I have looked in the documentation and forums and nothing touches this problem. Has any one any idea of what may be the issue or any clue on how to tackle it?
Below you find the code running in the microcontroller:
#ifndef __cplusplus
#define __cplusplus
#endif
#ifndef F_CPU
#define F_CPU 16000000
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "usart.h"
void sendTest(void);
void sendTest(){
USART0_Transmit8(0x07);
}
int main(){
DDRG |= (1 << PG0)|(1 << PG1)|(1 << PG2)|(1<<PG3); //Make pins PG[0...3] output.
PORTG |= (1 << PG0)|(1 << PG1)|(1 << PG2)|(1<<PG3); //Turn all LEDs off
PORTG &= ~(1<<PG0); //Turn red LED on
_delay_ms(30000);
PORTG |= (1<<PG0); //Turn red LED off
USART0_Init8(103);
while (1){
//test1echo();
PORTG &= ~(1<<PG0); //Turn red LED on
sendTest();
_delay_ms(1000);
PORTG |= (1<<PG0); //Turn red LED off
}
}
Take a look at how you have DIN wired up, and possibly your RTS signal.
I believe that if you hold DIN low (serial break), you can enter the XBee module's bootloader. If you don't interact with the bootloader for some amount of time, it will start running the XBee firmware. IIRC, this is what happens when RTS is high.
If RTS is low, booting with DIN low will start the XBee firmware in a default of 9600 baud and command mode. This is a recovery mode in case you don't know the module's baud rate.
You could use a pullup on that line, if the AT90CAN64 starts with that I/O pin as an input/floating.

Arduino Wifi ESP8266 error

i am trying to connect an arduino uno using esp2866 to my home router and i am getting th is error
C:\Users\john-\Documents\Arduino\newww\newww.ino:2:25: fatal error:
ESP8266WiFi.h: No such file or directory #include
^ compilation terminated. exit status 1 Error compiling for board
Arduino/Genuino Uno.
ESP8266WiFi.h is part of the ESP8266 core for Arduino. That core is used to add support to the Arduino IDE for directly programming the ESP8266. The file ESP8266WiFi.h is only accessible when you have one of the ESP8266 core for Arduino's boards selected from the Tools > Board menu. However, you are not directly programming the ESP8266 and do not have one of the ESP8266 core for Arduino's boards selected. You are programming the Uno and thus you will not be able to use ESP8266WiFi.h.
You need to use serial AT firmware on ESP8266 and connect the ESP8266 to UNO with two Rx and Tx pins. After that you will be able to send correct AT commands to open socket and communicate thru the Internet.
You can install AT firmware from here.
In the example given below, GPIOs on UNO 2 and 3 will be connected on the RX and TX of the ESP8266. Do not forget to cross connect the RX and TX on each other.
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(2, 3); // RX, TX for ESP8266
void setup()
{
Serial.begin(baud); // Serial for UNO output
wifiSerial.begin(9600); // Serial for ESP8266 AT input
}
void loop()
{
while(wifiSerial.available() > 0)
{
char a = wifiSerial.read();
if(a == '\0')
continue;
if(a != '\r' && a != '\n' && (a < 32))
continue;
Serial.print(a);
}
while(Serial.available() > 0)
{
char a = Serial.read();
Serial.write(a);
wifiSerial.write(a);
}
}
With this example, your SerialMonitor will be able to receive AT commands. You can write the AT command to connect to the Wi-Fi. Check some basic commands from here.
After you tested the commands and OK, you will put these commands into specific functions. i.e.:
void connectToWiFi()
{
//super simply
wifiSerial.write("AT+CWMODE=1\r\n");
wifiSerial.write("AT+CWJAP=ssid,pass\r\n");
}

Compilation error while uploading on Arduino Mega 2560

While uploading code on Arduino Mega, I am getting this error:
c:/users/sohini/desktop/arduino-1.5.2/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default':
(.vectors+0xdc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_55' defined in .text.__vector_55 section in
C:\Users\Sohini\AppData\Local\Temp\build208222592316456159.tmp/core.a(HardwareSerial.cpp.o)
Can anybody please explain what the error is about and how to correct it?
When trying to run the SoftwareSerialExample the problem for the mega 2560 is in the lines intended for the Leonardo. Comment out this code:
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
/*while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}*/

Can't send data to Xively through Arduino Wi-Fi Shield, sending just one stream

I'm doing a project involving uploading data wirelessly, from an analog sensor. In this case it is a light sensor.
I am using an Arduino Uno R2, and an official Arduino Wi-Fi Shield. Below is my code:
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>
char ssid[] = "Bradley's MacBook Pro"; // your network SSID (name)
int status = WL_IDLE_STATUS;
// Your Xively key to let you upload data
char xivelyKey[] = "SOP7lASYJVcRecV98zlHosDc9nLIAXqnDnIxRnXAmNeKorIk";
// Analog pin which we monitor (0 and 1 are used by the Ethernet shield)
int sensorPin = 2;
// Define the strings for our datastream IDs
char sensorId[] = "light";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(1125419529, datastreams, 1 /* number of datastreams */);
WiFiClient client;
XivelyClient xivelyclient(client);
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Starting single datastream upload to Xively...");
Serial.println();
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
int sensorValue = analogRead(sensorPin);
datastreams[0].setFloat(sensorValue);
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(15000);
}
However unfortunately every time I get this back in serial:
Attempting to connect to SSID: Bradley's MacBook Pro
Connected to wifi
SSID: Bradley's MacBook Pro
IP Address: 10.0.2.3
signal strength (RSSI):-20 dBm
Read sensor value 1023.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 1023.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
I noticed that after a few attempted it started to say No Socket available.
Does anyone have any clues as to where I've gone wrong?
I have resolved this problem. The issue is that I was using Arduino IDE 1.0.5 and there is a bug in that which prevents Wi-Fi communication. I have now changed to using an earlier IDE 1.0.2 and everything is running perfectly.
Even if you change IDE version to 1.0.2 , for few months it worked fine. If this problem occurs again, consider upgrading Wifi Shield Firmware . Latest package availble in Arduino site.It solved the error
Steps to follow for ugrading:
1. Download and install Flip from here. http://www.atmel.com/tools/FLIP.aspx You don't need to use or run the Flip program. There is a sub-program in the download you will need to use later. You will get to this sub-program (batchslip.exe) using a DOS command prompt. There is also a driver for the chip on the WiFi Shield (AT32UC3A or AT32UC3A DFU) that you will need.
If you recently installed a version of Arduino onto your computer, the software you need to update the WiFi Shield is in the Arduino directory structure. I know this to be true for me when I recently installed Arduino Version 1.0.5. (You might need to install a current version).
Connect your WiFI Shield to the Uno board. Put the jumper across both pins on 'DFU Programming Jumper'. Shown on 4th picture of the WiFi Shield on this page: ? http://arduino.cc/en/Main/ArduinoWiFiShield
To find the picture of the jumper, look for the words and arrow pointing to the board " DFU programming jumper (only used for updating shield firmware, leave unconnected for typical use)".
Connect power to your Arduino. Then connect a mini USB to the WiFi shield (not a micro-USB) and your computer.
Hopefully your Windows Device manager will show AT32UC3A DFU under "Other Devices". You may have to play with plugging/ unplugging power to Arduino and also the WiFI Shield's USB port connected to your computer. One time I had luck by not powering the Arduino and only plugging in the USB mini between computer and the WiFi Shield.
Right-Click on the device in 'Device Manager' and select "Update Driver" . I chose to install from my computer and directed the Device Installer application to Install from... C:\Program Files (x86)\Atmel\Flip 3.4.7 . I had an option to click "Include Subdirectories'. Sorry, I am not certain what sub-folder the driver might actually be in. When this step is complete, The AT32UC3A DFUshould be properly listed in Device Manager under "Atmel USB Devices".
Open a command prompt and navigate to the directory where "batchslip.exe" was installed by Flip. For me it was C:\Program Files (x86)\Atmel\Flip 3.4.7\bin ...but it depends where the Atmel software is installed and what version you download.
Once you are in the directory ( C:\Program Files (x86)\Atmel\Flip 3.4.7\bin) , you will need to run two commands. You will need to determine where you initially installed your Arduino software. I installed mine in C:\Arduino instead of the recommended lengthy folder suggested ( * something like C:\Arduino 1.0.5.) .. Therefore you might need to adjust the directory structure in the two commands I have listed below.
I suggest Cut and paste the first command from below, then make it match your * Arduino folder name. You may have to dump the following command in to a notepad or something to make sure there are no line breaks. Make the path as small as possible. Don't paste Arduino folder in program files while upgrading,because if path has Program Files (x86) ,spaces in between words will create un necessary error like : missing arguments
"
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf program verify start reset 0
"
Here is what you should see on the command line..........
Running batchisp 1.2.5 on Sat May 10 21:16:01 2014
AT32UC3A1256 - USB - USB/DFU
Device selection....................... PASS
Hardware selection..................... PASS
Opening port........................... PASS
Reading Bootloader version............. PASS 1.0.2
Erasing................................ PASS
Selecting FLASH........................ PASS
Blank checking......................... PASS 0x00000 0x3ffff
Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf
WARNING: The user program and the bootloader overlap!
Programming memory..................... PASS 0x00000 0x2902b
Verifying memory....................... PASS 0x00000 0x2902b
Starting Application................... PASS RESET 0
Summary: Total 11 Passed 11 Failed 0
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>
Now to update the second piece
Cut and paste the command from below. You may have to dump it in to a notepad or something to make sure there are no line breaks.
"
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf program verify start reset 0
"
Press Enter
Here is what will happen on your screen..
Running batchisp 1.2.5 on Sat May 10 21:34:04 2014
AT32UC3A1256 - USB - USB/DFU
Device selection....................... PASS
Hardware selection..................... PASS
Opening port........................... PASS
Reading Bootloader version............. PASS 1.0.2
Erasing................................ PASS
Selecting FLASH........................ PASS
Blank checking......................... PASS 0x00000 0x3ffff
Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf
WARNING: The user program and the bootloader overlap!
Programming memory..................... PASS 0x00000 0x3fe2b
Verifying memory....................... PASS 0x00000 0x3fe2b
Starting Application................... PASS RESET 0
Summary: Total 11 Passed 11 Failed 0
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>
Remove the Jumper from the WiFi Card. Remove the Min USB.
Verify Wifi shield with any sketch.
This method really solved the No Socket available issue.

Resources