[simpits-tech] Arduino and serial comms follow-up

dabigboy at cox.net dabigboy at cox.net
Thu Sep 20 20:31:43 PDT 2012


---- geneb <geneb at deltasoft.com> wrote: 
> 
> Matt, it looks pretty simple and straightforward.  Good job!
> 
> I'd rack the baud rate up to 250000 though. According to the rate chart I 
> have for the ATMega328, that's the highest rate you can use with a 0% 
> clocking error.

Well thanks! I was expecting something like "what the heck is that?" :) As you may have noticed, I did get the ordinal-to-integer codes from somewhere online, with little modification.

There is only one problem with the code I posted: it doesn't work. :P I ran it for a bit longer and it seems the Arduino gets stuck waiting for a while. I'm not quite sure what's happening.....I have a timeout of half a second on the reads for Python, which means it should eventually get past them and send something to the Arudino, which would make the Arduino kick off and go to the next call to Serial.Write(). I'm pretty sure it's nothing major, however. I'm just happy to see that I basically got it working. Cutting things down to one send and one receive per cycle might help as well. In fact, I'm thinking of sending and receiving every *other* cycle, which should help protect against Python or the Arduino getting stuck waiting again.

Thanks for the tip on the baud rate, I'll try it. I was just using 9600 because a lot of examples used it.

> One thing you might want to look at is using packets of binary data 
> instead of raw text.  I don't know how Python sends binary data though.

I may go this route. Python is sending its "string" object, which is basically a set of integers corresponding to the Unicode value of the character I'm sending. I don't know the down and dirty details exactly...I suppose this is clean enough to pass around to the Arduino. Unfortunately the standard write function in Pyserial only wants strings......that's why I'm using the funky code I lifted from online to pass large numbers from Python to the Arduino.

Matt


More information about the Simpits-tech mailing list