Wire library giving false readings on Arduino Uno (I²C) - arduino

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!

Related

Issue regarding TX line of Arduino while communicating with Vending machine via MDB Protocol over USART

I am trying to communicate with a Vending machine using MDB Protocol with the help of Arduino Mega and I am partially successful in doing so.
The circuit that I am using is attached here
While the circuit diagram is shown below
The Arduino Mega is communicating with laptop via Serial 1 and the vending machine communication is done via Serial 2 of Arduino Mega.
USART is being use for communication.
The strange issue that I am facing is, the communication with the vending machine starts sending data only when brown colored wires A and B are initially not connected(which are connecting Arduino TX to Vending Machine RX). Once I see the data coming from Vending Machine, I short wires A and B and Arduino Starts sending data to the vending machine too.
But if Wires A and B are connected on the start of a vending machine, the vending machine doesn't send any data to Arduino and hence no communication takes place. I want to make it work without manually connecting wire A and B every time.
I have tried replacing Optocoupler PC817C with
PC814
4N35
6N137 High Speed Optocoupler
I tried replacing Hex Inverter with
74HC04AP
I tried putting a mechanical and then solid-state relay between wires A and B and tried connecting them via external input but nothing happens
I tired adding an optocoupler as a switch between wires A and B and tried controlling it via firmware.
I even tried replacing the hex inverter with hex buffer HCF4050BE and a NOT Gate but regardless of any combination of mentioned components the issue remains the same, it only works if Wires A and B are initially not connected and then shorted once data starts coming from the vending machine.
I am using MateDealer's code.
I want to automate this manual process and need a simple solution for that.
Some time ago I had a communication trouble between a PIC18F452 and a vending Machine that uses MDB protocol.
In that time I found that the communication since PIC toward Machine is negative to communicacion since Machine to PIC. This is because the electronic into vending machine that receive data had a optoacoplade circuit that inverts signal.
I remember that I saw that when I read the MDB protocol documentation, the section when is the electronic diagram VMC.
I advice that check that section, this can explaine why when you conect the A and B wire job, because you are invert twice signal.
Resolved
The issue was due to a missed state machine element. My Device is a LEVEL-1 MDB Device and the vending machine that I am using requires the slave devices(whether they are at LEVEL-1 or LEVEL-2) to even respond to LEVEL-2 SETUP poll which is not a standard case in MDB Specifications Document.
Why it was working when TX wire was de-attached?
My logic analyzer was displaying some random hex values when TX line was removed and that random stuff caused the device to work.
By responding to the extra setup configuration poll of my vending machine I was able to make it work smoothly.
Below is the picture showing the configuration data sent by VMC which was discarded by my device making it behave strangely.

Arduino & ESP8266 - strange characters in response

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.

Raspberry Pi and Arduino Mega 2560 UART behaviour difference

I've been trying to establish serial (UART) communication between a Raspberry Pi Model B Revision 2.0 (checked the model like described on this page) and Arduino Mega 2560. I made a service on the Pi that writes to UART and then expects a message and a coworker programmed the Arduino with an echo program. While they were communicating, I had trouble receiving data, meaning that it was clustered in 8 byte pieces and I had to introduce a timeout for waiting between them (I was actually as much as available and calling select()for the next cluster but it turned to be 8bytes a cluster, except for maybe the last one. As explained in a question I found on this site, the programmer is the one to take care of the protocol and can not rely that the whole message will be ready to read at once (that is logical).
However, when I just connected Pi's TXD and RXD pins, no matter how much bytes I tried sending, it sends them in one go (I've gone up to a bit more than 256, that's more than enough for my purposes). I also have around 50 milliseconds of duration difference, measured directly from within the program, using gettimeofday() function.
So, could anybody clear things for me:
Why is this happening?
Is this difference in behaviour expected?
Is there a potential problem in either of the devices (if that can even be concluded from the given information).
Of course, any additional information is welcome, in case I forgot asking something that is deemed important.
Why is this happening?
I tried some time back communicating Arduino-Arduino and Arduino-Pi. I faced some problems with UART communication. However, you might want to keep same Baud rate on both the devices. With Pi, you might need to trigger an event if you receive data from Arduino. On the other side, if you code runs longer, then you might lose some data i.e. your Arduino code is running something else while Pi sends data over UART.
Is this difference in behaviour expected?
Yes. Arduino is a microcontroller based device while Pi is microprocessor based (runs on OS)
Is there a potential problem in either of the devices (if that can even be concluded from the given information).
I don't think there could be any hardware problem unless it is not functioning at all.
Also, because of this issues, I switched from UART communication to SPI communication. This solved my problem completely.

ESP8266 Point to Point communication with 2 arduinos

I am using 2 esp8266 wireless modules to establish bidirectional wireless communication between 2 arduino boards (one mega and one uno) without the use of any earth based technologies (i.e. radio frequencies, wifi which relies on earth sattelites, etc.). My solution was to use the esp8266 to establish a private area network with both esp's acting as a station and an access point (AT+CIPMODE=3). Unfortunately, this solution has proven to be more of a hassle than it was worth.
To start, I have the esp's each wired according to this diagram
When I first started out, the red LED was on and the blue LED was off. During this time, I was able to send AT commands, establish the server, and achieve the communication I required by entering commands directly to the serial monitor. After this, I started writing a library using the SoftwareSerial library to allow me to issue commands directly through the program to set up the esp as needed upon start up of my script. Before doing this, I changed the baudrate to make sure it was running at 9600, and entered the AT commands in the serial monitor to make sure everything was working properly and it still worked.
After I began writing the library, before uploading the code with a test of the library I noticed the blue LED was lit solid now. Noticing this, I reuploaded the barebones script (I haven't uploaded the library code to the arduino yet) and the esp was no longer receiving the AT commands.
Does this indicate an issue with the board which I can fix or does this mean the board is done?
With my deadlines approaching fast in about 3 weeks it is crucial I get this wireless communication working so if this is an issue with the board, I'm going to have to scrap the esp's and use a different way of communicating. So my second question is, if this is the case, what are other viable options for establishing this communication? I have used xbee's before and while that would be ideal, they fall out of the budget I have been alotted so I need to keep it under $50 for this. If bidirectional communication is not possible for that price I can live with one way because I just need to get this system working. Basically I just need to transmit a single byte of data.
I realize this response is a little belated, and I hope you got it sorted: I've started working with the ESP8266 myself in the last few weeks, and hence why I was looking around for tutorials on direct communication between 2 units, when I found your post.
From what I've been able to ascertain, the AT commands are a part of the 'firmware' which ships with some modules. The Arduino code however starts loading onto the chips at memory address 0x0000, which is the same address that the firmware update tools use.
In other words, I believe that with the Arduino-coded program running on there, you lose the AT command functionality.
If you find a firmware update tool for the ESP8266 (plenty online) you'll get back the AT commands.
I suppose though the real question is why would you want to? It seems that the AT commands are just a way to treat the ESP as a dumb WiFi antenna. With the Arduino code, you're actually treating it as a micro-controller in its own right.

How to write logic to handle arduino sensors on separate computer

The ArduinoIDE writes firmware to my Arduino UNO but I want to handle logic and code outside the microcontroller on the computer with the microcontroller strictly being a sensor and the computer handling the logic.
How can I have the computer handle the logic and listen to sensors (output data to a computer) and respond (input commands to the board)?
Is this done with serials? How do I get started with this?
I know how to code, I just need help understanding how to get the hardware to talk to one another. Arduino to computer, computer to arduino.
For example, I have a thermal sensor on the board, how can I have bi-directional communication where the output of temperature would go to a program on my computer and respond to the board to turn on an LED or other command based on statements on the computer.
All help is appreciated.
There is a tutorial on arduino.cc how to read a sensor on arduino en display the values in processing.
There is also a tutorial to turn on a led with a command from a pc.
If you want to do real complicated things I suggest that you take a look at Firmata

Resources