Pages: 1 ... 11 12 [13] 14   Go Down
Author Topic: SoftwareSerial with ATTiny84 using ATtiny library  (Read 48837 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1084
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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


* 155.jpg (38.79 KB, 483x445 - viewed 71 times.)
« Last Edit: December 10, 2013, 01:56:43 pm by Erni » Logged

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

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:
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:
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:
static SerialRelay RelaySerial( 12, 13);
in relaysoftserial.h

The output from serial monitor is this:
Code:
þÿ
--- 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?

Logged

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

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?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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);

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.
Logged

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

Quote

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...
Logged

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

How weird...

Code:
#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:
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...


Logged

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

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
« Last Edit: February 19, 2014, 09:20:06 am by Erni » Logged

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

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!
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Got it working, I was editing the wrong file!

Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well Its giving me knock-bang fault:15

What does this mean?

At least it's doing something...
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Is the processor running at the correct speed?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


What do you have connected to MISO?
Logged

Pages: 1 ... 11 12 [13] 14   Go Up
Jump to: