yllib1213
Posts: 6
Joined: Thu Dec 19, 2013 2:19 pm

Raspberry Pi connected to Arduino over USB High CPU

Wed Jan 08, 2014 1:13 pm

Hopefully this is the right section for this question. I have an Arduino Leonardo hooked up to my Raspberry Pi via a USB cable. The Arduino powers up and works fine. The problem I'm having is I am using the Pi GUI under startx to run the Arduino application which works ok. I'm able to upload my code to the Arduino and it runs fine. The problem I have is as soon as I launch the serial monitor my CPU utilization goes to the roof and stays there. The system basically becomes unresponsive causing menu's to open in 10's of seconds. It's odd because the application itself works fine uploading to the Arduino. I was doing a basic experiment where I was monitoring an input on the Arduino and sending the results to the serial window. I've done the same experiment on my iMac and it works fine. I have a work table I built to mess with the Pi, and so I'm trying to do my work there and avoid my Mac. Thanks in advance.
Billy

/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor

This example code is in the public domain.
*/

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1); // delay in between reads for stability
}

achrn
Posts: 438
Joined: Wed Feb 13, 2013 1:22 pm

Re: Raspberry Pi connected to Arduino over USB High CPU

Wed Jan 08, 2014 1:21 pm

Well you're trying to put 24000 bps (3 bytes once a millisecond) down a 9600 bps link, which seems a little optimistic.

What if you make your delay(1) be a delay(100)?

yllib1213
Posts: 6
Joined: Thu Dec 19, 2013 2:19 pm

Re: Raspberry Pi connected to Arduino over USB High CPU

Wed Jan 08, 2014 2:09 pm

Ah, makes sense. I did modify this setting but only after moving to my Mac. It was running fine on the Mac even at 1ms but I know the hardware is not comparable. I'll make that change and see how it does. That's some canned code I got from the Learning section of the arduino.cc site so I had not tried to make any changes to it. I'm kind of new to the Pi and Arduino so it actually took me a little while to notice that the code was set at 1ms and only after moving to the Mac. Thanks for the insight.

Billy

achrn
Posts: 438
Joined: Wed Feb 13, 2013 1:22 pm

Re: Raspberry Pi connected to Arduino over USB High CPU

Wed Jan 08, 2014 6:29 pm

Well, I'm not sure that it will resolve everything, but it might help, because at the moment something other than the delay() is presumably actually throttling how fast the arduino does its stuff. It may be, however, that the Mac can keep up, but the Pi can't. I'd make the code change and see what happens, but I wouldn't necessarily be heartbroken if it doesn't solve all the problems...

ChefBorjan
Posts: 6
Joined: Tue Jan 15, 2013 10:22 pm

Re: Raspberry Pi connected to Arduino over USB High CPU

Tue Jan 28, 2014 7:47 pm

Hi there.

A newbie here with a similar problem. So had this problem (also using RPi to control an UNO via usb, but using VNC to actually operate the RPi/Arduino IDE from my Mac), again appeared to be related to how fast data was coming at the ardunio via serial USB.

No delay in my program gave high CPU utilisation on the Pi, and made the serial monitor screen itself unresponsive and not usable.

Adding delay(100) or delay(10) and things work fine. So I take it this means the Pi can't handle data coming in at full speed? Is this because of the USB connection method?

Thanks.

User avatar
DougieLawson
Posts: 40789
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi connected to Arduino over USB High CPU

Tue Jan 28, 2014 7:53 pm

You can save a who bunch of pain by installing ino from http://inotool.org. There's no need to use an IDE, you can do everything on your Arduino from the command line.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

gordon77
Posts: 5450
Joined: Sun Aug 05, 2012 3:12 pm

Re: Raspberry Pi connected to Arduino over USB High CPU

Tue Jan 28, 2014 7:56 pm

I found with my python program sending data over USB from pi to uno l had to put a delay of 0.2s between them

Gordon77

Return to “Interfacing (DSI, CSI, I2C, etc.)”