Go Down

Topic: Programming Attiny45 with Uno. Problems finding good information. (Read 3334 times) previous topic - next topic

Richie_asg1

Hello folks,
 Had real problems finding one simple method to program the Attiny with the Uno today.

From all the instructables and google searches they seemed to contain errors or direct to one upload site on github that didn't work for me.

I did get it to work but only after following a link here and one on sparkfun and combining the two.

The link here is https://create.arduino.cc/projecthub/arjun/programming-attiny85-with-arduino-uno-afb829
 but links to the github link "attiny by Davis A. Mellis" which didn't work for me, nor did another link on the same site, and there is a lot of talk about the links not working all over the place.

The Sparkfun tutorial here - https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide

is great to download the attiny software and put it in the right folder for access and helped me a lot, and in my opinion is much easier to understand, but then wants you to use their programmer at £22 a pop - and I knew my trusty Uno in front of me could handle it.

It was a learning experience for me as a novice, but I just could not find a complete answer to what I thought was a well trodden route, as most of the "easy" tutorials out there used the Mellis information.

I'm sure there is plenty of good information to make it easy for an 8yr old, but I couldn't find it. Maybe someone can post a link to the easy and complete method, like a sticky in this part of the forum.


mixographer

I think this is a good place to start:

TinyCore

It talks about using usbASP, USBtiny and ArduinoAsISP. There is lots of detailed info and the Author Dr. Azzy is active here on the boards. 

Jimmy

pert

I 100% agree with mixographer about using the excellent ATTinyCore. However, I am curious:
but links to the github link "attiny by Davis A. Mellis" which didn't work for me, nor did another link on the same site, and there is a lot of talk about the links not working all over the place.
Which link are you talking about. The only one on that page related to damellis/attiny is the Boards Manager URL, which works fine for me. The only other link on that page is the datasheet from Atmel. The only mention of the link not working in the comments is a problem with the period at the end of the sentence being included in the URL, which was fixed 2 years ago. If you can identify an issue with damellis/attiny I will try to get it fixed. Even though there is a better alternative now, damellis/attiny has been around for a long time and a lot of people still use it, probably because they are reading outdated tutorials that don't mention ATTinyCore.

Richie_asg1

I think that could be the problem because I came in through the wrong door so to speak. I started by finding the chip then looking for methods to program it, rather than starting in Arduino and looking for suitable processors. It's the first I've seen mention of ATTinyCore from this direction.

Next step to cobble a shield together to make programming them a bit easier.

3Dtj

Question on compiling errors from an Uno to ATtiny45.  I've successfully compiled the blink sketch to the ATtiny45 but when I try the same process for a sketch involving a LoRa protocol I get a compiling error.  The LoRa sketch is not big thus confused on why I get a compiling error.  Are there certain operations (ie LoRa) that wouldn't be possible with the ATtiny45?

Appreciate any thoughts.
3Dtj

DrAzzy

Question on compiling errors from an Uno to ATtiny45.  I've successfully compiled the blink sketch to the ATtiny45 but when I try the same process for a sketch involving a LoRa protocol I get a compiling error.  The LoRa sketch is not big thus confused on why I get a compiling error.  Are there certain operations (ie LoRa) that wouldn't be possible with the ATtiny45?

Appreciate any thoughts.
3Dtj
Yes, absolutely - depends on how it interfaces with the LoRa radio. Post the error message for help interpreting it.

Particularly with David's core, you'll have issues converting a lot of sketches because of the lack of serial, I2C, and SPI hardware on the attiny's. With my core, I2C and SPI are done transparently using special versions of Wire and SPI library included with the core, so code should just work. There's also a "Serial" - but it's still software serial, not hardware serial, so it's subject to all the limitations of software serial (except that it uses the aco interrupt instead of a pcint, so it won't interfere with as much as softwareserial library)
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

3Dtj

Thank you for responding.  I'm new to all this thus but I was shocked when I got the compiling error for such a small sketch (only 50 lines of code).  I'll post the sketch and the error later this evening. 

Thank you and appreciate any insight.

3Dtj

3Dtj

The error message I get is that can not compilte to the ATtiny25/45/85.

Using two separate LoRa transreceivers, the program is intended to blink a LED upon receiving a message from the second LoRa transreceiver that broadcasts the correct syncword.  I was able to get the below code (modified to remove the serial print messages) using two Adriuno UNOs and two separate LoRa tranreceivers.


Currently I have the ATtiny45 wired with the LED going to ATtiny45 PB3, the IRQ to PB4, SCK to PB2, MISO to PB1, and CS PB0.  I was able to test the wiring and ATtiny45 using the basic blink program as described in the YouTube video to shrink your Adruino project.
 

/*
  LoRa Duplex communication

  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.

  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an

  created 28 April 2017
  by Tom Igoe
*/
#include <SPI.h>              // include libraries
#include <LoRa.h>

 
const int receiveLED = 3;
const int csPin = 0;          // LoRa radio chip select
const int resetPin = 5;       // LoRa radio reset
const int irqPin = 4;         // change for your board; must be a hardware interrupt pin

byte localAddress = 0xFF;     // address of this device
byte destination = 0xBB;      // destination to send to
byte syncWord = 0xB4;        // sync word (network ID)
byte spreadingFactor = 8;    // spreading factor (6-12)


void setup() {
  LoRa.setPins(csPin, resetPin, irqPin);  //set CS, reset, IRQ pin
  LoRa.begin(900E6);              // initialize ratio at 900 MHz

  LoRa.setSyncWord(syncWord);
  LoRa.setTimeout(10); 
  LoRa.setSpreadingFactor(spreadingFactor);
  // set the I/O pin modes;
  pinMode(receiveLED, OUTPUT);
  }
 
void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
}


void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  digitalWrite(receiveLED, HIGH);       // turn on the receive LED

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte msgLength = LoRa.read();    // incoming msg length
  String incoming = LoRa.readString();  //payload of packet


  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    return;                             // skip rest of function
  digitalWrite(receiveLED, LOW);      // turn off receive LED
}
}

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

The error message I get is that can not compilte to the ATtiny25/45/85.
I'm sure there is much more than that to the error. Being so vague will only make it less likely for you to get a solution. Do you see that black window at the bottom of the Arduino IDE window? It's called the console. When you have a compile error you need to scroll that window all the way to the top(helps to resize it larger) and start reading it from the top. You will find the compiler provides you specific information about the problem.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

3Dtj

Sorry about the mix-up on the code.  I'll resend using the proper </> and give the exact message later this evening. 

Thank you,
3Dtj

3Dtj

First here is the original code that I was using to compile to the ATtiny45.

Code: [Select]


/*
  LoRa Duplex communication

  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.

  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an

  created 28 April 2017
  by Tom Igoe
*/
#include <SPI.h>              // include libraries
#include <LoRa.h>


const int receiveLED = 3;
const int csPin = 0;          // LoRa radio chip select
const int resetPin = 5;       // LoRa radio reset
const int irqPin = 4;         // change for your board; must be a hardware interrupt pin

byte localAddress = 0xFF;     // address of this device
byte destination = 0xBB;      // destination to send to
byte syncWord = 0xB4;        // sync word (network ID)
byte spreadingFactor = 8;    // spreading factor (6-12)


void setup() {
  LoRa.setPins(csPin, resetPin, irqPin);  //set CS, reset, IRQ pin
  LoRa.begin(900E6);              // initialize ratio at 900 MHz

  LoRa.setSyncWord(syncWord);
  LoRa.setSpreadingFactor(spreadingFactor);
  LoRa.setTimeout(10);
  pinMode(receiveLED, OUTPUT); // set the I/O pin modes
}

void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return
  digitalWrite(receiveLED, HIGH);       // turn on the receive LED

  // read packet header bytes
  int recipient = LoRa.read();          // recipient address
  byte msgLength = LoRa.read();    // incoming msg length
  String incoming = LoRa.readString();  //payload of packet


  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    return;                             // skip rest of function
    digitalWrite(receiveLED, LOW);      // turn off receive LED
  }
}





Below is part of the error message.  Unfortunately the rest exceeds the 9000 character limit so I just pasted a portion of it to give you an idea.



Code: [Select]


In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from sketch\LoRaDuplex_ATtiny45.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h: In member function 'void SPISettings::init_AlwaysInline(uint32_t, uint8_t, uint8_t)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:146:16: error: 'SPE' was not declared in this scope

     spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |

                ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:146:27: error: 'MSTR' was not declared in this scope

     spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |

                           ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:146:65: error: 'DORD' was not declared in this scope

     spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |

                                                                 ^

In file included from C:\Users\TBK\Documents\Arduino\LoRaDuplex_ATtiny45\LoRaDuplex_ATtiny45.ino:14:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::beginTransaction(SPISettings)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:203:5: error: 'SPCR' was not declared in this scope

     SPCR = settings.spcr;

     ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:204:5: error: 'SPSR' was not declared in this scope

     SPSR = settings.spsr;

     ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h: In static member function 'static uint8_t SPIClass::transfer(uint8_t)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:209:5: error: 'SPDR' was not declared in this scope

     SPDR = data;

     ^

pert

Do this:

If you still get errors then post them.

3Dtj


3Dtj

Ok this is what I got this time after installing the new core.

Code: [Select]


Build options changed, rebuilding all
C:\Users\TBK\Documents\Arduino\libraries\arduino-LoRa-master\src\LoRa.cpp: In member function 'int LoRaClass::endPacket()':

C:\Users\TBK\Documents\Arduino\libraries\arduino-LoRa-master\src\LoRa.cpp:150:11: error: 'yield' was not declared in this scope

     yield();

           ^

exit status 1
Error compiling for board ATtiny25/45/85.

wilykat

Code: [Select]
'yield' was not declared in this scope

Looks like your code has a bug. A missing line or a typo somewhere.

Go Up