I've been trying to send commands from a Raspberry PI 3 to an Arduino using the I2C bus with the Smbus library.
The code is written so you can send PWM value from the raspberry to the arduino to drive motors while the arduino is returning variables about motor speed.
The detection is working and the program runs several epochs until it crashes throwing Error 121 Remote I/O.
After lots of search on the web I tried to apply fixes to overcome the issue but nothing seems to work.
Python Code throwing errors
bus.write_i2c_block_data(0x13, 0, data) # Error 121 after a random runtime
block = bus.read_i2c_block_data(0x13, 0, numBytes) # Error 121 after a random runtime
I am exploring next solutions:
Force program to rerun on errors (smbus throwing error cause the whole script to stop)
Set i2c clock frequency
Use time.sleep in program to let the I2C commands completely execute
It seems that the connection become unstable when changes occurs to the motors (speed, direction), there is possibly noise from these charges on the circuit.
Is it possible to ignore error, flush the bus for extra informations and restart de process?
Thanks a lot for your help.
After more research I found a post on raspberry stackexchange pointing to the issue I faced.
https://raspberrypi.stackexchange.com/questions/104975/how-to-automatically-rerun-python-script-if-error-occurs
while True:
<all your code>
if <some error occurs>:
time.sleep(10)
continue
the proper statement is to use try and except IOError calling continue on error
while True:
try:
bus.write_byte()
except IOError:
continue
This ignore bus communication error and continue running the program. On next epoch the function will run again.
Looking for a way to clear the bus with left datas.
Related
I'm working on an Arduino Uno + ESP8266 project.
I try to use them as a web server on Wi-Fi network to control a motor that connects to Arduino - basically a trigger system that receives signals via Wi-Fi. Currently, I've successfully connected ESP8266 to my access point by sending AT commands from Arduino. Another client on the same network can statically access ESP8266's assigned IP address.
However, when I try to catch some HTTP queries (I want to use them as conditions to control the motor) I occasionally encountered the non-ASCII characters in HTTP request. I use serial comm to debug, please look at the screenshot in the link below:
Arduino - Computer serial communication for debugging
The line ",519:POST ..." should contain a complete number following "/?", but there's some strange characters instead. So I cannot determine the input data to control motor. Once in a blue moon, the expected format of request shows up as follows:
The correct data received
There's no issue with the HTTP response part, even though I got the uninterpretable request, I can still send the JSON error message back to client.
Attempt Note:
The Arduino uses different serial ports to talk to computer and ESP8266. Since the connection can be established, and the data being sent, I believe that the baud rate is simply correct on both side. (115200 for ESP8266, 9600 for computer - also tried 115200 for both and got the same result)
I use V3.3 from Arduino as power source for ESP8266. But I also use voltage regulator to smooth out the current as many people suggest that. The problem still remains.
I'm struggled with this issue for a few days, just want to know if anybody had the similar experience, or could give some clue for the next step.
After a considerable effort to stabilize the circuit, I switched to NodeMCU and got the system working perfectly. I assume that ESP8266 alone is somehow not robust enough without other components, which I unfortunately have no knowledge on.
So I'd like to close this thread with a short recommendation for anybody struggling with the same issue to switch to NodeMCU (which would replace both Arduino and ESP8266); if that could support the requirement.
I have a strange issue with one of my wifi based projects where the entire loop seems to slow down and take 5 seconds to respond (it has an embedded web server).
I have serial debugging commands in my code, but when the code is running on the target hardware, there is nothing connected to the serial monitor. Could that cause me an issue? Should all Serial commands be commented out prior to final deployment and if they should is there an easy way to do this?
Do your serial pins are used for any connection ?
if yes, then you have to commented out the serial commands that do not related to the connected hardware.
If no , then there is no need. it just consumes some microseconds of your operation time.
I came across this website when trying to find a reliable way to use the watchdog for preventing failures (code lock ups) and saving battery using an Arduino.
I tried the code and it worked fine. However, i would also like to use the serial monitor. I tried adding Serial.begin(9600); in the setup, however, most of what is shown in the serial monitor (from the code within the main loop) are strange characters (the baud rate is set to 9600). Is this something to do with the function to configure the wdt and the placement of Serial.begin(9600) in the code?
I'd also like to use an external interrupt (via a button on Digital pin 3) to wake the board from sleep. How can be achieved based on the current code? I know how to implement using a different method of making the board go to sleep without using any watchdog at all, however, i have been unsuccessful in making it work with this code.
Many thanks for any help.
As said above, the serial communication should work fine. Are you sure you are able to make your serial communication work fine without the watchdog part of the code? I have used the watchdog tips given on the website along with serial communications without any problem on Arduino Uno, so I would guess the serial communication problem lies somewhere else in your code.
Can you write a bare bone example of your code with the watchdog management part, a serial communication or two somewhere in your loop(), and if you want some delays / infinite loops to test the watchdog firing, post it here, test it on your board and indicate if / where you have problems?
I have never used a pin interrupt, but it seems that google gives some nice results with example code. Have you tried the results given by google?
https://www.arduino.cc/en/Reference/AttachInterrupt
http://www.allaboutcircuits.com/technical-articles/using-interrupts-on-arduino/
You will have to be careful regarding the choice of the pin on which you put the interrupt, as explained in the Arduino Reference only pins 2 and 3 support interrupt on the Uno.
I'm trying to get I²C communication working between a Raspberry Pi using the python-smbus package and an Arduino Uno using the Wire library.
I'm currently sending one byte from the raspi to the arduino, which stores it and then sends it back upon the request of the raspi.
This works very well at first, but a few seconds after starting the script (around 500 to 4000 sending/reading cycles), the arduino will start to get false readings. These persist until the arduino is restarted, and restarting the python script and/or the raspberry pi doesn't make a difference either. For this reason, I'm sure that the problem is on the side of the arduino.
By using the serial monitor, I've determined that the arduino actually does receive (or thinks it receives) this wrong number.
The number is wrong in a very specific way: It is left shifted by one and a one is appended to its end.
If there's any additional information you'd like, please do tell me. Thanks!
I often get ERROR_SEM_TIMEOUT errors using the WinUSB WritePipe function. This would seem to indicate that there is a timeout, but if I wait a period of time and try again I'm never able to write. I'm writing in 64 byte chucks to the USB device and often don't have problems. Once I start getting the error, I may have to unplug the USB and and close my app before trying again. Has anybody experienced this problem?