Serial communication between esp32 and iRobot Scooba 450 - serial-port

I am looking to modify my Scooba 450 vacuum to make it remotely controlled.
So I searched and came across this and this.
After trying different ways, I ended up getting it to work in python, with a computer running at 57600 baud. So far, so good.
But for it to be remotely controlled, I wanted to use an ESP32, I tried a lot, but I can't communicate with the robot.
Normally, when it is charging, it returns information about its battery. So I put it on charge, and tried to read his data with the ESP32, but no information comes in.
I tried connecting it directly with a micro USB to micro USB cable, but without result.
I also of course checked that the cable is working, that data is currently being sent from the Scooba.
The program:
void setup() {
Serial.begin(57600);
}
void loop() {
while (Serial.available()){
Serial.print((char)Serial.read());
}
}
My goal would be to be able to control it from a site, but before that, I must succeed in communicating with the Scooba. I don't necessarily need to be connected to the computer to know if data is being received, because I can see if the LED on it is on.
Thanks

Related

ESP32 Switch Between Promiscuous and STA Mode

I'm working on a project based on the ESP32 platform. The aim is to count the number of MAC addresses in the area, and transmit this information over WiFi (using an http POST request).
The first task is achieved by sniffing WIFI packets and collecting the contained addresses, following this example: https://blog.podkalicki.com/esp32-wifi-sniffer/
I believe that the code which "sniffs" the packets sets the ESP to run in promiscuous mode, and therefore I cannot connect to any AP anymore.
I've tried several solutions, first starting with timer interrupts. However this approach always led to a Core Panic and reset of the chip.
I also learnt I could use RTOS to run different tasks in parallel on the two cores of the CPU, but that didn't help to solve the problem.
void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type)
{
if (type != WIFI_PKT_MGMT)//aggiungere filtro su RSSI a questa altezza.
return;
const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
//some analysis and then print the MAC address
}
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &chUpdate, true);
timerAlarmWrite(timer, 1000000, true);//timer, arr_val, reload=true
delay(4000);
wifi_sniffer_init();
timerAlarmEnable(timer);
}
// the loop function runs over and over again forever
void loop() {
//Serial.print("inside loop");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Establishing connection to WiFi..");
}
Serial.println("Connected to network");
}
I also noticed that the code in the loop gets stuck into the while, and is restarted every time the packet handler is run (I nevere get to see "Connected to network", but i see "Establishing connection to WiFi.." several times.
Anyone can explain me what's going on? Is there a different approach to achieve this result?
Thank you.
You may have two tasks and two cores, but the ESP32 still has only one wifi chip. The way your code is written (at least, the code you shared), you'll be trying to connect to a wifi network at the same time as you're trying to run promiscuous mode. You can do only one of those things at a time.
You'll need to stop promiscuous mode before you attempt to connect to an access point. Right now your code constantly attempt to connect to a wifi access point. Use a volatile variable to store the current mode - promiscuous or connected. Change it when you need to change states. Only attempt to connect to wifi when the variable says you want to be in connected mode.
There may be some code you need to run to turn off promiscuous mode when you change states, before you connect to a wifi access point.
If you're using wifi_sniffer_init() from the example you linked to, that code isn't meant to be run in an Arduino Core application. It does some network initialization that the Arduino Core will also do. It may not be safe to do that twice (it might work, it might not... but it's definitely not intended to be done that way).
You're setting an interrupt handle chUpdate() which you didn't share. I'd bet that's the cause of your Core Panics. You can do very little in an interrupt handler. You definitely can't call most Arduino Core functions or most ESP-IDF functions. Most code isn't protected against interrupts, so the timer interrupt can occur while data structures are in an inconsistent state. Re-entering code can corrupt the data structures and cause the kind of crash you described. You're best off setting a volatile variable and waking up a task that will do the work you need done while not in the interrupt handler.
Finally, you should call WiFi.mode(WIFI_STA); before you call WiFi.begin().
For anyone confused about why you can't connect to a wifi network while in promiscuous mode - what ESP8266 and ESP32 call "promiscuous mode" is really "wifi monitor mode", which lets you monitor a wifi radio channel and see all wifi frames sent on it. They use the term "promiscuous mode" differently from the rest of the industry. Usually "promiscuous mode" means seeing all the packets being sent on the network (wifi or hardwired) that you're connected to.
I know that it's been just over a year but THANKS to the info provided by romkey I think I solved this problem within my app by calling this routine before connecting to WiFi to upload MAC data.
void end_Scan_WiFi() {
esp_wifi_set_promiscuous(false);
esp_wifi_stop();
}
Followed by this ...
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,pass);

Arduino Uno serial monitor printing garbage

I am using an Arduino Uno and GSM sim800l for a project. It looks like something is wrong and I don't know what it is. Here is my code:
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
void setup() {
Serial.begin(19200);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(19200);
altSerial.println("Hello World");
}
void loop() {
char c;
altSerial.print("altSerial is working.");
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
Its output was like this:
AltSoftSerial Test Begin (linebreak)
Hello World (linebreak)
ltSerial is ok⸮⸮M⸮ɥ⸮⸮⸮is okalt //insert long random garbage here
I tried changing the baud rate of the code and serial monitor to keep it matched, but it is not working. I tried to lower it as low as 300 and tried up to 19,200 baud as well.
I also tried menu Tools → Fix encoding and reload, but it still didn't solve the problem. It is my first time using this type of hardware, so please bear with me. My goal is to use it to send SMS messages. but right now I'm trying a smaller task with it to try and understand it better.
The Arduino IDE version I am using is 1.8.7.
It is a troubleshooting tree:
I am going to assume the system is Windows 10, but the basic ideas are the same if the way to achieve them are different.
Plug in your Arduino. You already said your serial monitor is set to 19200, but be sure you are sure, because that is very often the problem.
if you are sure of #1, open Control Panel → Device manager → Ports
If you don't see "Ports" in the list, then your computer isn't seeing the Arduino. This could be anything from a bad Arduino to a bad cable to a bad USB port on your PC. Try switching all those out one at a time to see if you can get anything talking to the COM port at speed. Since you were getting something in the serial monitor, this won't be your particular problem.
Click on "Ports" to expand it, and verify you see the Arduino listed. Right click on the Arduino, disable, and enable it again. See if that fixes the baud rate problem.
Look at Arduino properties
Does it say your device is working properly? If no, look at events and you will see an error description. Fix whatever it says is wrong. If yes, continue.
Port settings will likely be 9200, 8, None, 1, None. Even if your baud rate in the serial monitor window is 19200, you will still probably see 9200 in Device Manager, don't worry about it. It feels wrong, but it is normal. Microsoft seems to like keeping 9600 here, even if the last thing I did with this port was different. The data bits, and other settings listed above are a different matter.
next, click on Advanced
is your Arduino-assigned port number showing up? Does it say 'In Use' beside it? If it does, this is your problem. I know. Strange, huh? Trust me, if it says 'In Use', that means that something internal to Microsoft is using the port, but it isn't your Arduino. Power shell can help you resolve what has it, but that's another story, but the best bet now is reinstall your driver.
Click the Driver tab, and verify your Driver Provider is Arduino LLC. I've never seen it not that, but if it isn't, I would try to find out why.
Go ahead and Update the driver and reboot your computer, even if you aren't prompted to reboot, do it anyway.
Didn't fix it? In the Driver tab, Disable the device, and re-enable it. That might fix the problem, too.
Didn't it fix it? Don't uninstall the driver just yet.
Click Details. Do you see Arduino?
Look at the Events tab. If you see an error, then fix it.
Still not working? Uninstall your serial driver, and reinstall it.
Still no 19200? If you have garbage, the timing on your RX pin is not synchronized with the Arduino TX pin. You now need a logic analyzer, and that is more than can be covered here.

Arduino Sends Old Data Through Serial

I think my problem would best be explained with an example. Here is some Arduino Code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(millis());
delay(1);
}
...and here is the output:
Now, those numbers at the beginning aren't just your regular old first-bytes-of-serial-data-are-always-messed-up numbers. Those numbers are left over from the last time I opened the serial monitor. How do I know this? Because I counted how many seconds had gone by since I last opened the serial monitor, and it all matched up.
So here's the big questioroonie,
How do I make this stop? It's breaking my java program that's supposed to read data from the Arduino's current "run instance"(I don't know the correct term), and not the last one.
There is nothing wrong with your Arduino. Remember, the USB connection is not a real RS-232 serial interface, it's simulated through USB. And that USB connection is controlled by a chip with its own buffer.
Bad news is, nothing you can do if you're using the USB cable to carry your RS-232 signals, other than to send some "filler characters" to purge the buffer. Too many buffers everywhere :) Send some terminal emulation commands like "clear the screen" and "form feed" etc. to empty the pipeline of stuff in the buffer.
Which reminds me -- we should all quit using the crummy Arduino serial monitor and be vocal about it. Instead, use TeraTerm or Putty or any other good-quality terminal emulator of your choice.
Or connect with real RS232 and an adapter and cable. My development machine has three serial ports, but that's what I do. Often computers today don't even have one handy.

My Arduino Uno Wifi, stops responding to wifi

My new Arduino Uno Wifi, stops responding to wifi if left inactive. To be more specific, after 2-3 hours of no wifi usage:
I cannot access the build-in configuration page of the Arduino's wifi section
Loaded programs which use Wifi are not receiving any commands via my browser
loop() continues to run just fine
It somehow seems that the wifi section of my Uno Wifi "sleeps" after some arbitrary interval.
Using code to periodically reset the board (by sending HIGH to the reset pin of the board) did not solve the problem. As soon as the reset takes place, loop() starts executing just fine, but wifi connection is still impossible to obtain.
Things I usually do to gain access to my board AFTER wifi is lost:
Hard reset the board (unplug power and plug it again) -> almost always works
Try to access arduino from several different wifi devices hoping that the board somehow "wakes up" -> occasionally works but only after 4 or 5 minutes (sometimes hours) of failed attempts
My router seems to be fine. Another web server which I have set up in a wifi-connected laptop has had no hiccups (even after a long time of inactivity). Moreover I've never had any connection problems with my router so far.
This is giving me a hard time! Could anybody be of any help?
Is my Arduino Uno faulty?
Many thanks in advance
George
Here's my configuration:
Arduino Uno Wifi Developer edition (built-in wifi support)
Arduino IDE 1.8.0 (I'm using the Linux version installed on Ubuntu 12.04 )
I have already connected my arduino to my home network and gave it a static IP 192.168.2.50
WIFI mode: STA
Wifi channel: 1
SLIP status enabled
MQTT status disabled/disconnected
code:
int i=0;
void setup() {
pinMode(13,OUTPUT);
}
void loop() {
if (i==1){
digitalWrite(13, HIGH);
i=0;
}
else{
digitalWrite(13,LOW);
i=1;
}
delay(1000);
}
It seems that I have been a victim of an extreme ambiguity caused by the .org fork of arduino.
Arduino.cc and Arduino.org boards are NOT 100% compatible with each other.
To be more specific, the examples that come with the IDE (and are based on the the wifi shield of arduino.cc) DO NOT function with aruduino-uno-wifi (the one with the embedded wifi section)
Apart from that, it seems that arduino-uno-wifi has firmware that is way behind the arduino.cc (in terms of features as well as code quality). This has frustrated several users as you can see here:
Issue 2: Rename this fork and use less confusing versioning
Issue 10: Please stop doing this !
Issue 6: Remove old licenses from sample code comments and take credit for everything
If you are interested of an arduino.org view of things visit here:
The full story
All of the above is information which I wish I had when ordering my new ardnino-uno-wifi board.
Moreover it is relevant with the question I've asked, since it indicates that my problem is most probably a bug of the uno-wifi board, so I should file a bug report (and keep hoping) instead of trying to fix my code.

Reading serial data from Arduino fails

I have written a program for Arduino that reads some analog signals and sends them to the computer when it receives a command from the master computer. I wondered why this didn't work on the computer it was intended to run on. On my own computer it runs fine.
I uploaded a simple test code in the Arduino.
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available()) {
Serial.println(Serial.read());
}
}
This doesn't run on the second computer either. When I use Arduino serial monitor for transfering data, I see the RX led blink but not the TX. With the computer it's working on, I can see both of the leds flash. Arduino receives the data on both computers, but the second computer doesn't receive Arduino's responses. What might be wrong?
Edit. I forgot the Arduino hooked up to the problematic PC for a few minutes and tried it again. Then it worked! It seems like it needed some time to warm up. Why's that?
Sometimes it can take a second for the Arduino and computer to establish the Serial handshake, especially at 9600 baud. I'm glad you got it working!

Resources