For a simulation project, I use an Arduino to simulate the evolution of a fan's speed as a function of a temperature, all connected to a Siemens PLC.
Then I save the data in a csv file via a pyhon script on raspberry pi 3.
All the programs work well, I susceed to control the motor (connected to the arduino) from the PLC and record the data sent on the rasp in a csv file. But the problem is that I have an offset in my recording. For exemple, when I put the fan's speed to 80% I receive a valeur around 85-86% on the rasp. Same thing for the temperature, I got an offset in my measurement (for example I receive 29°C instead of 23°).
Even if I program my arduino directly from the Rasp, I got this offset on the serial monitor whereas on pc (instead of the raspberry card) I don't have any offset in my logs.
I think that the problem is from by usb-serial communication between arduino and raspberry but I don't know why...Any idea ?
As you're reading an analog value I guess (you failed to provide a wiring diagram of your setup) the value read by the Arduino depends on it's USB voltage which may vary, depending on the USB host.
Thank you to responding me and sorry for the lack of details.
Here is a diagram of my actual setup (in attachment) --> The Raspberry is connected to the "Arduino Uno 2" with a usb-serial communication.
I receive the data on the raspberry from a serial connection with the arduino (In fact, the raspberry pi card feeds the arduino and recovers the values with the same wire which is maybe probably the origin of my problem).
Do you have a solution to troubleshooting that ? I tried to plug my arduino with the Jack DC connector in addition to the usb-serial wire, but I have the same issue on the rasp (Same thing on the serial monitor before executing the python script).
(In fact, the raspberry pi card feeds the arduino and recovers the values with the same wire which is maybe probably the origin of my problem).
What do you mean by "recovers the values"?
Do you have a solution to troubleshooting that ? I tried to plug my arduino with the Jack DC connector in addition to the usb-serial wire, but I have the same issue on the rasp (Same thing on the serial monitor before executing the python script).
Please describe in detail what that problem is. How do you know that you see other values on the Raspberry Pi than you expect? Do you measure with an analog meter? You don't provide enough information!
first of all, thank you for taking the time to answer me and sorry if I wasn't clear enought.
pylon:
What do you mean by "recovers the values"?
I mean the values received by the rasp from the arduino.
pylon:
Please describe in detail what that problem is. How do you know that you see other values on the Raspberry Pi than you expect? Do you measure with an analog meter? You don't provide enough information!
In fact, you right. After some checks, the values read by the raspberry are the same as those displayed by the arduino's serial monitor. But the problem comes from the arduino which does not transmet exactly the good values it receives from the PLC. For exemple when I set the fan's speed at 80% on the PLC, the arduino receive a value varying between 79% and 85%, it oscillates.
For example, if I set the fan speed to 100% on the PLC, I am supposed to receive 5V on the arduino. Then it interprets this value as equal to 255 and so it also converts for a speed of 100%. When I put a multimeter at the PLC output, I get 5V, but when I measure at the arduino output (before transmission to the rasp) I get a value of 4.88V that varies slightly.
And so it disrupts my transmission and I try to figure out why
Here are some pictures that may better explain my problem As you can see, when I set "80%" of fan's speed on PLC, I receive around "81%" on PC (that should be okay) but, on raspberry, I receive around "85%"...
Maybe your first supposition about the USB Host Voltage it's true (if we compare the pc and the rasp), but I don't know how to fix it because I really need to use a raspberry to record my datas :).
Looks like the raspberry Pi can only supply 4.76V to the Arduino uno whereas the PC can get the USB voltage much closer to 5V.
You can check this by measuring the 5V rail on the Arduino when it is plugged into each source.
The fix for this is to power the Arduino via it's 2.1mm power socket with somewhere between 6V and 12V (9V is an ideal value allowing 4V across the on-board regulator). Do ensure the external power supply you use can deliver at least 1A.