Go Down

Topic: How establish communication between Attiny and Arduino One? (Read 6602 times) previous topic - next topic

Jomarumu

Jul 15, 2014, 08:50 pm Last Edit: Jul 15, 2014, 09:25 pm by Jomarumu Reason: 1
Hi
I having some troubles, I need make something like this:

If one button is pushed, the Arduino Uno is informed, it could be done with digital and analog entrances, but I need more than 40 buttons and it should be done with only one wire for data.


This is my code for ATTINY: (sending 1.5 in the last line, because I do not know how send the float point "ponto")
Code: [Select]

#include <SoftwareSerial.h>

float ponto = 1.0;
int rxPin = 2;
int txPin = 3;
SoftwareSerial ATTSerial = SoftwareSerial(rxPin, txPin);

void setup()  {
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 ATTSerial.begin(9600);
}

void loop()
{
 mySerial.print("1.50");
 delay(100);
}


And for Arduino:
Code: [Select]
float c;

void setup()
{
 Serial.begin(9600);
 pinMode(8, OUTPUT); //not used now
 digitalWrite(8, LOW);

}

void loop()
{
  if(Serial.available() > 0) {
     c = Serial.parseFloat();
     Serial.println(c);
  }
}


I see in the Monitor Serial sometimes 1.50, and then the monitor serial don't show anything more.
What is wrong here?

And how make the Attiny send the float point?

Thank you.

fungus


What is wrong here?


SoftwareSerial.

It never works.

Use I2C, SPI ... anything except SoftwareSerial.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Jomarumu



What is wrong here?


SoftwareSerial.

It never works.

Use I2C, SPI ... anything except SoftwareSerial.


I don't will use a computer to monitoring it.
In this case I will have a lot of Attinys and 1 Arduino Uno with LCD, this LCD should show the float, for exemple, if I push the button float = 1.0, else, float = 1.5, and for another Attinys the same think (but 2.0, 2.5, 3.0, 3.5 ...), what would be the better solucion? I2C

And thank you for the answer.

fungus


what would be the better solucion? I2C


Yes.

http://playground.arduino.cc/Code/USIi2c



And thank you for the answer.


Karma is awarded on the left (with the little green cross....)

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Jomarumu


Yes.

http://playground.arduino.cc/Code/USIi2c

Karma is awarded on the left (with the little green cross....)

Thanks.

And I don't see where is the Karma, maybe it is because I sign in today, just to answer this, so, at this time I can't award nobody.

Tom Carpenter

#5
Jul 16, 2014, 11:09 am Last Edit: Jul 16, 2014, 11:22 am by Tom Carpenter Reason: 1
Alternatively, if you want to use serial, there is another way.

I presume (unless I am missing something) that an Arduino One is an Uno?
If so you can put it into Synchronous mode, by calling these lines in setup() of the Arduino sketch:
Code: [Select]
Serial.begin(2400); //the actual baud rate will be 4 times higher in sync mode, so this is 9600.
UCSR0C &= ~_BV(UMSEL01);
UCSR0C |= _BV(UMSEL00);


Connect the XCX pin (Digital Pin 4) of the Arduino to an interrupt pin of the ATTiny (you can either use the Analog Comparator AIN1 pin, or either the External Interrupt 0 or 1 pins depending on which ATTiny you have). Then connect the RX and TX to any pin on the ATTiny on the same Port as the interrupt pin.
I have attached a library which will allow the ATTiny to be a USART slave. In this library there is a "TinyUSARTConfig.h" file. Set the port bits and names you have used in this file as directed. If you used an interrupt different from INT0, you need to configure that as well.

And the following is an example sketch:
Code: [Select]

#include "TinySoftwareUSART.h"
#include "TinyUSARTConfig.h"

USARTRingBuffer rx_buffer = {{0},0,0};
USARTRingBuffer tx_buffer = {{0},0,0};//These two lines are required and are the Serial comms buffer.

TinySoftwareUSART USART = TinySoftwareUSART(); //Make an instance of USART

void setup()
{
   USART.begin(); //No need to specify a baud rate, as that is governed by the Arduino Uno (master).
   USART.println("Welcome!");
}

void loop(){
   if (USART.available()){
       USART.write(USART.read()); //echo.
   }
}


Basically this gives you the advantage of Asyncronous Serial communication, but uses a clock line to time the bits allowing for full duplex operation without the ATTiny having to time out the Serial baud rate.


(Side note, I have tested this on two different ATTiny devices, but it should work on any which have the GPIOR0, GPIOR1 and GPIOR2 listing in the register description of the datasheet, those are used by the library).
~Tom~

fungus


I have attached a library which will allow the ATTiny to be a USART slave. In this library there is a "TinyUSARTConfig.h" file. Set the port bits and names you have used in this file as directed. If you used an interrupt different from INT0, you need to configure that as well.



I'm fairly sure he has many Tinys talking to an Arduino Uno, in which case that's all backwards (not useful).

The only bus that easily allows multiple devices to be attached to it is I2C.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

fungus


If one button is pushed, the Arduino Uno is informed, it could be done with digital and analog entrances, but I need more than 40 buttons and it should be done with only one wire for data.


Another way to do it (probably much easier) is to use shift registers or I2C expander chips to provide more input pins for your Uno.

eg. 74HC165 (shift register) or PCF8574A (I2C I/O expander)

Which is easier to implement depends on how your input buttons are arranged.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Tom Carpenter


I'm fairly sure he has many Tinys talking to an Arduino Uno, in which case that's all backwards (not useful).

The only bus that easily allows multiple devices to be attached to it is I2C.

Ah, hadn't picked that up from his post. Yes, if you have multiple devices I2C is by far the best bus.
~Tom~

Docedison

#9
Jul 18, 2014, 01:09 am Last Edit: Jul 18, 2014, 01:15 am by Docedison Reason: 1
The I2C bus does have some length and loading issues..About 20 cm and a max of about 400 pF. It was never intended for wired use as I2C means Intra Integrated Circuit.. On one board, not a meter of wire per leg. A basic rule of thumb for I2C is that, more devices on one bus require lower value pull-downs to minimize the effects of bus loading.
RS485 is much better suited for this purpose as it is a long distance multi-drop communications protocol and MAX485's are inexpensive and easy to use. RS485 breakout boards are inexpensive on FleaBay..

Doc
Edit for clarity.. Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Go Up