Sending multi digit serial numbers to the arduino.  - Page 1
Forum section: electronics / general

author: Mcfly
author_rank: Contributor
timestamp: June 27, 2012, 05:39:15 am
content: Im working on my widget, and i need a way to send an 8 bit binary number to the arduino. I know how to send a single digit number to the arduino, but I'm running into ascii problems and who knows what else. Has anyone ever done this before, and can point me in the right direction?

author: Rerouter
author_rank: Super Contributor
timestamp: June 27, 2012, 07:36:11 am
content: when you mean binary, why would ascii be involved? you send it as a byte, arduino accept bytes, its the conversion to decimal or what ever standard you want to follow, if not decimal or hex might require a look up table,

author: ejeffrey
author_rank: Super Contributor
timestamp: June 27, 2012, 07:44:24 am
content: The easiest, most portable, and most generic way is to convert your number to a decimal ASCII string. You use sprintf() or the equivalent on your host and use the int() conversion function on the arduino. If you are using native C on your microcontroller you want the strtod() function.The only real downside to that is that it isn't very efficient. A 2 byte word can take up to 6 characters. This is not a problem for most applications, but if you need high throughput or low latency and are stuck with the slow RS232 port you can do better with binary data.

author: NiHaoMike
author_rank: Super Contributor
timestamp: June 28, 2012, 04:54:28 am
content: Just send it on the line. 8 bits (one byte) is the standard "unit" size on RS-232 so you don't need to do any framing. Things get much more complicated when sending sequences of multiple bytes. A good way of framing uses a signal that cannot possibly be a data value. In RS-232, it can be done by sending a "break".

author: electrode
author_rank: Regular Contributor
timestamp: June 28, 2012, 09:35:52 am
content: Not enough info in question. Give us an example of what you're trying, what you want, and what you're getting.Communication should be trivial. I use pySerial.

author: bsiswoyo
author_rank: Newbie
timestamp: August 09, 2012, 01:03:52 am
content: Quote from: Mcfly on June 27, 2012, 05:39:15 amplease visit my blog about this:http://bsiswoyo.lecture.ub.ac.id/2012/08/arduino-tutorial-how-to-turn-onoff-8-led-using-visual-basic/best regardbambang siswoyo

author: Unknown
author_rank: Unknown
timestamp: August 14, 2012, 01:23:54 pm
content: Quotehi, are you sure the source code is in the file "Source_LEDWidget_Arduino.rar" ?

author: Unknown
author_rank: Unknown
timestamp: August 14, 2012, 01:58:19 pm
content: I've never used Arduino only Microchip but a quick Google around and it looks really easy using the Serial.Read like ... "incomingByte = Serial.read();"Just make sure that if you're using VB6 etc that you're actually sending the number as a byte and not a byte sequence of ascii values.

author: bsiswoyo
author_rank: Newbie
timestamp: August 17, 2012, 10:59:13 am
content: hi jucole.Yes, there are a setup file and source code freely can be downloaded.

author: Unknown
author_rank: Unknown
timestamp: August 17, 2012, 06:50:45 pm
content: Quote from: bsiswoyo on August 17, 2012, 10:59:13 amhi , I see the Arduino code and the vb6 setup exe etc, but the vb6 code "Form1.frm" is not in the rar file "Source_LEDWidget_Arduino.rar" ?

author: jeremy
author_rank: Super Contributor
timestamp: September 09, 2012, 10:48:05 am
content: This is a pretty sneaky problem, I'm sure there is a libc way to do it but I usually justCode:uint32_t get_number(char size) {uint32_t output_number = 0;for (char i=0; i<size; i++) {// get some characters, convert ascii into the actual number, add it in// note that '0' is 48, the ascii code for the zero characteroutput_number += Serial.read() - '0';output_number *= 10; // shift everything up by one digit}}This assumes that you send digits in the most significant to least significant order ie if you want to send 1234 you would send '1', '2', '3', '4'. So to get an 8 digit number you would just goCode:uint32_t num = get_number(8);But using a 32 bit integer on an 8 bit micro is really inefficient, you should just store it in an array and process it from there.Code:#define NUM_SIZE 8char buffer;for (i=0; i<NUM_SIZE; i++) buffer = Serial.read() - '0';Good luck!