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")
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
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:
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:
#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).
Jomarumu:
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.
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..