ATtiny85 and Arduino SoftwareSerial

Hi,

How do I use SoftwareSerial to pass an integer from the ATtiny to the Arduino?

Pulling my hair out!

Thanks

Hi,

An integer is 2 bytes long and can hold numbers in the aproximate range -32,000 to +32,000.

When you send data over a serial line (software or hardware), it has to be sent one byte at a time. So you can’t send an integer as such, it is too large. You must have your attiny break down the integer into byte sized pieces before you send it, and then reassemble the pieces back into an integer after your Arduino has received it.

There are several ways to break down the integer. One way is to use highByte() and lowByte() functions. Another is to use Serial.print() or sprintf() to convert the integer into several bytes in decimal format.

Paul

You can use Serial.print(int), like PaulRB says, to send from the tiny and Serial.parseInt on the Uno end.

PaulRB:
Hi,

An integer is 2 bytes long and can hold numbers in the aproximate range -32,000 to +32,000.

When you send data over a serial line (software or hardware), it has to be sent one byte at a time. So you can’t send an integer as such, it is too large. You must have your attiny break down the integer into byte sized pieces before you send it, and then reassemble the pieces back into an integer after your Arduino has received it.

There are several ways to break down the integer. One way is to use highByte() and lowByte() functions. Another is to use Serial.print() or sprintf() to convert the integer into several bytes in decimal format.

Paul

Hi Paul,

Do you have an example of how to use it? And how to connect the ATtiny to the Arduino to do this?

Thanks

blues1143: Do you have an example of how to use it? And how to connect the ATtiny to the Arduino to do this?

I don't, but have you searched the forum, the playground and the internet in general yet? If you have not even found any examples of how to connect the attiny and the arduino for serial comms, how come you are pulling your hair out already?

Tell us more about your project. Is it a school assignment?

I searched everywhere and only found one solution that worked! Its for a car daytime running light controller.

The solution was to use TinyWires on the attiny and wires on the arduino. Got it all working now!

Just gotta find the feed that goes live when the car unlocks now! Job for the weekend I think…

You can use sprintf() function to "convert" the integer to a C string, transmit it using Serial and then use parseInt() or atoi() functions...

Have a look around to see the syntax and uses of these functions.

Or you could use a C union if you like the fancy stuff.... Have a look here for an example sending a float http://forum.arduino.cc/index.php?topic=43670.0