Serial Comms question


hi all,

quick background - im communications engineer, understand electronics, im hopeless programmer! please bear me,

im working on project requires bidirectional serial data transfer between 2 arduinos (in case nano , mega). im not going start complex though, , need head around transferring data 1 of them other,

now, data in question in form of individual binary inputs needs displayed decimal equivalent. not strictly binary though, comes groups of 4 or 5 switch contacts in 'sort' of bcd. each switch represents 1 unit of radio frequency, i.e. 1 switch khz value, 10khz etc etc,

at other arduino, or start on serial monitor guess, need display actual decimal value, of switches, in order, show actual frequency,

as example, imagine frequency 123.4khz has binary equivalent of 1111 1111 11111 111

you idea...

what im not @ sure how data transferred serial link. understand it, done 1 byte @ time? right in thinking need conversion of bianry decimal before sending values on link, decimal values?

so, example - read 4 input pins connect say, nkhz switch, convert decimal equivalent, send number serial? or read , convert switches until have whole set of decimal values full frequency, , send them large integer?

the goal here read frequency setting switches (there 6 of them!), send value other arduino, , display decimal frequency on lcd (which somewhere between 2,000.0mhz , 29,999.9mhz). create frequency display remote radio switches on.

i intend start learning how setting 1 arduino set of dip switches mimic radios frequency switches (just 1 @ first) , sending data serial monitor, move mimicing whole switch bank , displaying full frequency (around 19 inputs!), there move displaying on lcd of other arduino.

so advice can give on getting first stage working helpful!

regards
martin

decimal text representation of byte (or int or ...). can either convert text @ sender or @ receiver.

serial.print/ln conversion you, serial.write transfer binary. serial monitor display ascii (text).

you can collect data 1 set of dipswitches single byte (it fits in nibble , hence 2 sets of dipswitches fit in byte). can collect dipswitches in (unsigned) long (6x4 =24).

code: [select]

void loop()
{
  // read dipswitches; data collected in byte
  byte dip1 = readdip1();
  serial.print(dip1);
}

if dipswitches e.g. set 1001, result in serial monitor text "9".

you want send data if there change in dipswitches; there statechange detection example in ide. trick remember last reading , compare current reading , send on change.

for reliable communication, need form of packets it's clear start of packet , end of packet is; communications engineer should clear you. can have @ serial input basics - updated; describes receiving of packets e.g. serial monitor. replace 'serial monitor' 'other arduino' , have idea implement @ sender.



Arduino Forum > Using Arduino > Programming Questions > Serial Comms question


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor