2

I am using an Arduino Uno to sample a signal. I then want to send those samples in a block to the Raspberry Pi. At the moment I am simply using

(on the Arduino side) Within loop

Serial.write(value)

(on the Raspberry Pi side, in python)

import Serial
fromArd = serial.Serial('/dev/ttyACM0',9600)
while True:
    try:
       val = ord(fromArd.read())
       print(val)

This results in some values going missing (due to work queuing). Does anyone know how I can make sure the RasPi receives ALL the data it is sent?

I've used MPICH Message Passing Interface before but the Arduino doesn't have an OS, so I'm not sure how I can use it or if it would work.

Is there possibly another way of doing this by only sending data when the RasPi is willing to read it? Would this be interrupt driven or based on polling every time I want data to be sent?

Thanks, E.Lee

Extra explanation: I know that some data was 'missed' or 'dropped' because the input to the Arduino was a sine wave and when I plot the results from the RaspberryPi there are phase changes in the sine wave. For example the values are slowly increasing then suddenly become zero and start to increase again. OR One cycle is measured as expected but the next cycle does not line up.

The RaspberryPi is not a real time device. My suspicion is that when I send data to it while it's doing other things (eg GPU) it doesn't read the data.

I looked at the data coming out of the Arduino when connected to my laptop - the wave form was exactly as expected so I think it is an issue with RasPi rather than Arduino.

7
  • 1
    I don't really understand how RaspberryPi can miss some data in your case. Could you explain some more? Jul 17, 2013 at 17:45
  • I've added more explanation in the question now.
    – E. Lee
    Jul 18, 2013 at 8:32
  • You are sending your data at very low speed and serial data should be buffered by kernel so unless RapsberryPi is realy very busy, it shouldn't drop anything. Jul 18, 2013 at 9:30
  • I aim to send data at 10kHz but found this problem at only 100Hz.
    – E. Lee
    Jul 18, 2013 at 13:52
  • How busy is really busy? Do you know how I can reduce how busy it is?
    – E. Lee
    Jul 18, 2013 at 13:53

2 Answers 2

1

You have to start troubleshooting from the other end, from the beginning of data. Make sure your adruino really captures your sine wave fully. I suspect, when your duino is sending the block of freshly captured data the capture routine is not called and this results in missing samples.

Besides that, there are time proven data control signals used in serial transfers, XON/XOFF in software or RTS/CTS in hardware. Use them.

2
  • I also suspected that was the case but I was able to confirm it wasn't, by looking at the output from the Arduino (via the serial monitor provided by Arduino software). I use a timer interrupt to sample data so I wasn't sure how it would cope if I was sending data while the interrupt occurred. However, as I mentioned, I can get the expected data using my own laptop. I'll look into XON/XOFF and let you know if it fixes the issue, thank you for suggesting it.
    – E. Lee
    Jul 18, 2013 at 13:59
  • Lenik could you perhaps link me to a good tutorial/website with regards to XON/XOFF? Thanks
    – E. Lee
    Jul 19, 2013 at 12:55
-1

You need flow control. Here's a hardware way to do it: http://forum.arduino.cc/index.php?topic=18813.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.