Go Down

Topic: SoftwareSerial with ATTiny84 using ATtiny library (Read 54067 times) previous topic - next topic

Erni

#180
Dec 10, 2013, 07:52 pm Last Edit: Dec 10, 2013, 07:56 pm by Erni Reason: 1
Quote
Tiny Core 1 has been packaged for Arduino 1.5.  


FYI it also works with 1.5.5

Now we can have line numbers, and also info about dynamic memory.
This is the blink sketch on a t85

Code: [Select]
Sketch uses 804 bytes (9%) of program storage space. Maximum is 8,192 bytes.
Global variables use 11 bytes (2%) of dynamic memory, leaving 501 bytes for local variables. Maximum is 512 bytes.
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

Hasseklas

Hi all,

I am trying to get the serial relay to work with an attiny84 and arduino uno. I have had some help from Erni in another thread but now I need som information again.

I have built a "shield" for programming the attiny84 which works excellent. Seven pins are connected to the arduino (incl. a reset capacitor) in standard fashion.

Now I wanted to use the shield to also function using software serial. So I tried ernis code(http://www.ernstc.dk/arduino/tinycom.html) with a small modification:
Code: [Select]
include <SoftwareSerial.h>
// Attiny84 and TinyISP Serial Relay


const int rx=PA4; //receive pin on attiny pic any; changed from PB1 in ernis code
const int tx=PA5; //MISO on attiny is also tx

SoftwareSerial mySerial(rx, tx);
void setup() {
mySerial.begin(9600);
}

void loop() {
if(mySerial.available()>0){
mySerial.println(mySerial.read());
}

mySerial.println("ttt");
delay(1000);

}

Above the code (on ernis webpage) it states that "Transmit on Arduino is pin A0" which is consistent with this statement
Code: [Select]
static SerialRelay RelaySerial( 12, 14 );
in the relaysoftserial.h in TinyISP.

So instead of soldering a new connection on the shield connecting (PB1) to AO I wanted to use PA4 which is already connected to pin 13 on the arduino.
so I change to
Code: [Select]
static SerialRelay RelaySerial( 12, 13); in relaysoftserial.h

The output from serial monitor is this:
Code: [Select]
þÿ
--- Monitor starting ---
ttt
ttt
ttt
ttt
ttt



which means the transmit from the tiny is working but I also send characters during this which are not getting back.

Suggestions?


Hasseklas

So, I used the breadboard style programming and hooked up the rx from arduino to pin 7 and the tx on the tiny to PA7 but no avail.

I checked the the signal from the arduino pin 7 and it is high until I send digits through the monitor, so it seems the attiny does not receive.

Is this a tuning problem? If so, would it no be similarly affecting the transmit from the attiny?

Coding Badly

Quote
[font=Courier New]const int rx=PA4; //receive pin on attiny pic any; changed from PB1 in ernis code
const int tx=PA5; //MISO on attiny is also tx

SoftwareSerial mySerial(rx, tx);[/font]


You are comingling code that expects Arduino pin numbers with I/O port bit numbers.

http://code.google.com/p/arduino-tiny/source/browse/cores/tiny/pins_arduino.c#162

PB1 is digital pin 1.  PA5 is digital pin 5.

Hasseklas

Quote
http://code.google.com/p/arduino-tiny/source/browse/cores/tiny/pins_arduino.c#162

PB1 is digital pin 1.  PA5 is digital pin 5.


Agreed!

As I tried to state in my second post I now use PA7 on attiny (physical pin 6, digital pin 3) connected to arduino pin 7.

I see how this:
Quote
the rx from arduino to pin 7 and the tx on the tiny to PA7
can seem a bit confused.

What I meant was the tx on arduino is assigned pin 7 (in relaysoftserial.h) and the rx on attiny is assigned to PA7.   

I will now test all pin positions on the attiny to rule out any assignment error...

Hasseklas

How weird...

Code: [Select]

#include <SoftwareSerial.h>
// Attiny84 and TinyISP Serial Relay


const int rx=PA7; //receive pin on attiny pic any
const int tx=PA5; //MISO on attiny is also tx

SoftwareSerial mySerial(rx, tx);
void setup() {
mySerial.begin(9600);
}

void loop() {
if(mySerial.available()>0){
   
mySerial.println(mySerial.read());
}

mySerial.println("ttt");
delay(1000);

}


works on physical pin 10 (digital pin 7, PA3 according to :  http://code.google.com/p/arduino-tiny/source/browse/cores/tiny/pins_arduino.c#162)

Now I'm really confused...

changed to
Code: [Select]
const int rx=7; without moving the connection and it still works.

I guess I should stick to digital pin numbers if I can huh...



Erni

#186
Feb 19, 2014, 03:17 pm Last Edit: Feb 19, 2014, 03:20 pm by Erni Reason: 1
I'm afraid that I am to blame for  the confusion.

I have corrected the pin names/numbers here

http://www.ernstc.dk/arduino/tinycom.html

You can use this reference sheet to see both digital and analog pinnumbers.

http://www.akafugu.jp/images/microcontroller-reference-sheet.png

For example physical pin 10 is digital 7 and analog 3
so:
digitalWrite(7,HIGH); will set physical pin 10 (or PA3) high
analogRead(3);  will read from physical pin 10 (or PA3)

BTW
PA3 is short for PortA pin3

Hasseklas

Thanks a lot. I think i get it now. PA7 defaults to 7 since it refers to the analog port and it is assumed not to be used other than in analog read. When used in digital write it still defaults to 7 but it then adresses digital pin 7.  Your previous code worked since analog 5 and digital 5 is the same pin.

Thanks a lot for the help guys!

chalupien

Hi, I am able to get the ATTINY84 to blink and using the TinyISP and the Knock Bang I can get the console at 19200 to show the instructions if I send it "?" and start it using "!"

But I dont get any ouput from the ATTINY84

What could be the problem, Ive been working on this for quite sometime.


chalupien

Also if I try to use the SoftwareSerial I get the error that SoftwareSerial does not name a type...

Any ideas how I can get this to work?

chalupien

Got it working, I was editing the wrong file!


chalupien

Well Its giving me knock-bang fault:15

What does this mean?

At least it's doing something...

Coding Badly


Is the processor running at the correct speed?

chalupien

Not sure how to verify other than uploading the 8mhz bootloader. Which I did..

Coding Badly


Go Up