c - Reading a Tx from a barcode scanner with a Arduino Mega 2560 - RS232 -


for past couple of days have been trying create program reads tx of barcode scanner. have tried bunch of different things such different programs different scanners. sample program wrote example:

#include <softwareserial.h> softwareserial myserial (50, 51); unsigned char incomingbyte;   void setup () {     serial.begin (9600);     myserial.begin (9600);     serial.println ("begin initial serial!\n"); }  void loop () {     while(myserial.available () > 0)     {         incomingbyte=myserial.read ();         serial.print (incomingbyte,hex);     }     serial.println (); } 

at time can not provide proper connection diagram (will when have chance), arduino mega 2560 connected 3 wires barcode scanner, tx (pin 50), rx (pin 51) , gnd

background info on transmitted data: startbit: 0x02 stopbit: 0x03

ultimate goal: scanner scans barcode, arduino reads datastream , sends output when recognizes code.

how achieve ultimate goal?

thanks in advance!

arduino 2560 pin 50 , 51 ttl level signals. need provide rs-232 driver invert , level shift signal.

an example driver max232cpe.

http://www.surplus-electronics-sales.com/index.php?main_page=product_info&cpath=15&products_id=828&gclid=cjv7vnwim8ocfyoeaqodsjqdfq

also, softwareserial supports option invert logic level. arduino page:

inverse_logic: used invert sense of incoming bits (the default normal logic). if set, softwareserial treats low (0 volts on pin, normally) on rx pin 1-bit (the idle state) , high (5 volts on pin, normally) 0-bit. affects way writes tx pin. default value false.

warning: should not connect devices output serial data outside range arduino can handle, 0v 5v, board running @ 5v, , 0v 3.3v board running @ 3.3v.

arduino softwareserial reference page


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -