Pages: 1 [2]   Go Down
Author Topic: Attiny85 Communication with Arduino UNO  (Read 2496 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 3
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Tiny will run up to 20 MHz with a crystal. You're not using a crystal, which means that it runs at the internal 8 MHz oscillator. Additionally, if you haven't changed the default fuses, it's set up for clk/8, so runs at 1 MHz.

Also, if you disable the reset pin to use it as an analog input, you can no longer serial-program the chip; you have to use "high voltage" programming, which requires a special programmer (most ICSP programmers can't do this.)

I find that I end up using SPI for the Tinys for all communications. This requires three wires (clock, data in, data out) and you either don't need to use chip select, or you can use the data-in wire as also chip-select by pulling it low for a bit before you send the start of a new packet (and write code to expect this on the receiving Tiny.)

Another option, which I like more these days, is to use a Tiny84A, which has more pins, and still an ADC, or a Tiny2313, which has even more pins, but no ADC, or a full Atmega328p. The few extra dollars for the mega328p aren't particularly noticeable if you only build one or a handful, but the time you save by having enough pins is huge :-)
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1029
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No you don't have to include anything (it is in the Tiny core). My  example above is all that is needed.
It also means that you cannot change the TX pin it is PB3  1).



1) ofcource there are exeptions, like if you use a Xtal
« Last Edit: November 27, 2012, 05:55:27 pm by Erni » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Erni, so I used your sketch and the links to the cores you sent me. However, out of the pin, to the arduino, I'm only getting the same garbage from the serial monitor.

I read that you can change the frequency of the chip by choosing your board and frequency and choosing burn bootloader in the tools menu. I put a link to a picture of this here: http://imgur.com/f6hqD

The code on the UNO itself shouldn't matter though correct? It should still receive data on the RX pin and print to the serial regardless right? Or do I need to have code on the UNO that reads in the data and then outputs it to the serial monitor?

EDIT:
So I found the quote below explaining what the y character means. I confirmed this by loading the code below onto the Arduino UNO and printing:
Code:
I received: -1
to the serial monitor. However, I do not understand why there is no data to read. I'm printing the string "Hello World", so it seems that it should see some sort of data.

Quote
The y with the two dots over it is caused by printing a -1 as an ASCII character. The -1 comes from trying to read data from the serial port, when there is no data to read.

Code:
//Arduino UNO Read Data COM Test
int incomingByte = 0;   // for incoming serial dat

void setup()  {
  Serial.begin(9600);
}

void loop()
{
  
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
 
}
« Last Edit: November 27, 2012, 07:41:26 pm by a_soy_milkshake » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code on the UNO itself shouldn't matter though correct? It should still receive data on the RX pin and print to the serial regardless right? Or do I need to have code on the UNO that reads in the data and then outputs it to the serial monitor?

If you are using the Uno as a serial-to-USB converter you need to hold the Uno processor in reset.  Put a jumper between RESET and GND.

This will help...
http://arduino.cc/forum/index.php/topic,123388.msg932099.html#msg932099
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I do that I get no output on the serial monitor. If I remove the jumper I see the same character garbage. The sketch I'm using now is very simple and should just print out hello world.

Code:

void setup()  {
  Serial.begin(9600);
}

void loop()
{
 Serial.println("Hello World");
  delay(10);
}
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Put a jumper between RESET and GND on your Uno.  Put a 220 ohm (or higher) resistor between TX on your ATtiny85 and TX on your Uno (ATtiny85 TX is connected to Uno TX through a 220 ohm resistor).
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Apparently I was not clear in Reply #18.  If you use your Uno as a serial-to-USB converter and you fail to hold the Uno processor in reset and you fail to include a series resistor between your Uno and your ATtiny85 you could damage your Uno, your ATtiny85, or both.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2926
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int incomingByte = 0;

why do you have it as an INT? your trying to read a string of characters not ints. change it to either "string" or "char".

now since your getting an entire string, you was to concatnate the incoming chars into the string you sent.

try this:

Code:
string incomingByte = ' ';
.
.
.
void loop()
 {
   incomingByte += Serial.read();

if(incomingByte =="\n") //new line indicates you got all the chars
   {
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte);
    incomingByte = ' '; // clear for new data
   }
}
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Following the instructions you provided in reply #20 worked perfectly. I'm finally printing out the string. I misunderstood your instructions in replay #18. Thank you so much. This is one headache gone.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

While we are waiting to see what coding Badly has in his sleve

@a_soy_milkshake doesn't seem interested so I guess it stays up my sleeve.   smiley-grin
Logged

Pages: 1 [2]   Go Up
Jump to: