Go Down

Topic: attiny 85, any pointers?/ (Read 21 times) previous topic - next topic

skootles

#60
Dec 19, 2012, 08:30 pm Last Edit: Dec 19, 2012, 08:32 pm by skootles Reason: 1

It works well on the 85? I think I'll go ahead and get some of those, then. I assume I'll have to change the pin assignments in the library? From PORTA to PORTB, that is.


Keep in mind that you'll only have one digital pin left on the ATtiny85 if you do this. That pin is actually the RESET pin, so you need to set a special fuse on the microcontroller, and afterwards you'd have to use a high voltage programmer to program it. See this thread for more details.

It's really best to just try and get it working on an ATtiny84.

Shrugs

I guess I'll keep working on it. I don't know enough about the SPI protocol to actually debug the thing, though.

Is this to be run on a 1mhz chip or an 8mhz?

I'm going to try running the same code on the ATTiny and change the uno code to RF24 to see if that picks up any data.

winner10920

For my situation with the 85, it worked fin because all I need is cs to be a dedicated pin, the rest are multipurposed for other things, and I used it on 8mhz

Shrugs

Right, because with the CS HIGH, the transceiver will ignore all the other pins. Smart.

Davste

#64
Mar 25, 2013, 11:54 pm Last Edit: Mar 25, 2013, 11:57 pm by Davste Reason: 1
This is an old thread but I can't get this to work. I have Shrugs' scripts running, one on my ATTiny85 and one on my Arduino Mega.

Here's my Arduino Mega pin layout:
(Starting from top left pin of NRF (IRQ), where bottom right pin is GND)
Arduino Mega - nRF24L01
N/A - IRQ
50 (MISO) - MISO
51 (MOSI) - MOSI
52 (SCK) - SCK
48 - CSN
53 (SS) - CE
3.3v - VCC
GND - GND

And the NRF to the ATTiny Layout:
ATTiny - nRF24L01
1 (Reset) - N/A
2 (PB3) - CE
3 (PB4) - CSN
4 (GND) - GND - Arduino GND
5 (MOSI) - MISO
6 (MISO)- MOSI
7 (AI, SCK) -SCK
8 (VCC) - VCC - Arduino 3.3v
I have tried swapping around MOSI and MISO on both the mega and the ATTiny with no luck.
If I add an LED (+) to PB4 in parallel, and ground it properly… I see it blinking every 3 seconds. So something is happening.

The problem is that with both scripts running, the receiver doesn't seem to receive anything.
I modified the reciever pins from the scripts a bit. Here they are:

Mega (reciever):
Code: [Select]
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
byte data[32]; //size of payload
void setup(){
 Serial.begin(9600);
 //begin nrf24ll01
 Mirf.cePin = 53; //Mega
 Mirf.csnPin = 48; //Mega
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();

 Mirf.setRADDR((byte *)"reply");
 Mirf.setTADDR((byte *)"sendr");
 Mirf.payload = 32;
 Mirf.channel = 8;
 Mirf.config();
 Serial.println("Setup finished");
}
void loop(){
  Serial.print(".");

 if(Mirf.dataReady()){
   Mirf.getData(data);


   delay(50);
   for (int i = 0; i < 32; ++i)
   {
     Serial.print(data[i]);
     Serial.print(",");
   }
   Serial.println();
 }

 delay(200);
}


ATTiny (didn't change anything):
Code: [Select]
#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>
#include "SoftwareSerial.h"



byte data[32] = {
 'T','T','W','I','R','E','L','E','S','S','Q','Q','Q','Q','Q','Q',
 'Q','Q','R','J','F','E','D','O','R','Q','Q','Q','Q','Q','Q','Q'
};

SoftwareSerial mySerial(9,10);

void setup(){
 mySerial.begin(9600);
 mySerial.write("ATTINY - Setup\n");
 
 // pinMode(3,0);
 pinMode(0, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 // digitalWrite(3,1);
 delay(1000);
 
 Mirf.cePin = 2; //attiny
 Mirf.csnPin = 3; //attiny
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();

 Mirf.setRADDR((byte *)"sendr");
 Mirf.payload = 32;
 Mirf.channel = 8;
 Mirf.setTADDR((byte *)"reply");
 Mirf.send(data);
delay(3000);
mySerial.write("ATTINY - End Setup\n");

}

void loop(){

 delay(1000);
 digitalWrite(0, HIGH);
 mySerial.write("ATTINY - Sending... \n");

 Mirf.send(data);
 digitalWrite(0, LOW);
 delay(100);

}



Shrugs

I wouldn't use any of my scripts; I never got the thing working. I eventually bought two ATTiny85s and it works. Are you using the attiny85 library on the Mega? If so, that's what's causing the problem. Try using the RF24 library on the Mega and the attiny85 one on the 85.

Davste

#66
Mar 26, 2013, 11:08 pm Last Edit: Mar 27, 2013, 05:32 pm by Davste Reason: 1
OK, so I'm trying to use this script with the RF24 library on the Mega.

Code: [Select]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

// Setting up mega on 48 and 49.

RF24 radio(49, 48);


const uint64_t pipe = 0x8; //Problem might be here with cross-communicating between RF24 and Mirf

void setup(void)
{
 Serial.begin(57600);
 printf_begin();

 //Start radio
 radio.begin();

 //Setting a smaller packet size:
 radio.setPayloadSize(8);

 // Open pipe for reading:
 radio.openReadingPipe(1,pipe);
 radio.startListening();

 radio.printDetails();
}

void loop(void)
{
 

   // Wait here until we get a response, or timeout (250ms)
   unsigned long started_waiting_at = millis();
   bool timeout = false;
   while ( ! radio.available() && ! timeout )
     if (millis() - started_waiting_at > 200 )
       timeout = true;

   // Describe the results
   if ( timeout )
   {
     printf("Didn't get anything...\n");
   }
   else
   {
     // Read the response:
     unsigned long response;
     radio.read( &response, sizeof(unsigned long) );

     // Spew it
     printf("Got something! %lu",response);
   }

   // Try again 1s later
   delay(1000);
}


There's a screenshot of the thing running. From the config it spews out, I think the pins are wiring is set up correctly.
What I don't know is...

If I've set the channel on the ATTiny (using Mirf) with:
Code: [Select]
Mirf.channel = 8;
WIll it work if I set it on the RF24 with:
Code: [Select]
 radio.openReadingPipe(1,0x8);

I will add the updated ATTiny code soon... it's not working at the moment.
I do have two ATTinys, but I would like to make it work from one ATTiny85 to an Arduino first preferably.


Davste

I'm really surprised by the lack of interest here. This is a great combo and people have got it working! At the cost of £10, you can have your own wireless sensors, complete with onboard processing and batteries that last for more than 2 years if done correctly. These things can fit in a very small and confined space, and reading on them, they seem to have a decent (line of sight) range and great reliability. They'll just stop sending when not in range, they won't send garbage. So, why isn't there a plethora of information on this combination? I'll post my code if I get it working, anyway.. but I'm starting to doubt it at this stage.

fungus

I've used the nRF24L01+ before and they work pretty well.

But that discussion probably needs a different thread.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

fungus


I wouldn't use any of my scripts; I never got the thing working. I eventually bought two ATTiny85s and it works. Are you using the attiny85 library on the Mega? If so, that's what's causing the problem. Try using the RF24 library on the Mega and the attiny85 one on the 85.


Is an nRF24L01 useful on a Tiny85? It would need all 5 I/O pins to connect it.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Davste

That's true, BUT you can either re-program the reset pin... OR you can just disable the wireless card temporarily while you obtain readings, then re-enable it and send them (with the CS pin I think)

fungus


That's true, BUT you can either re-program the reset pin... OR you can just disable the wireless card temporarily while you obtain readings, then re-enable it and send them (with the CS pin I think)


I guess it could be made to work. Much easier to use a Tiny84 though (unless you're trying to save cents on huge quantities of devices).
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Davste

I've managed after five days of mucking around with it :)
Remember to try different channels. That may have been one of the problems for me.
Here's the code I'm using right now (that works):

Mega:

Code: [Select]


#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

byte buffer[] = {0,0};
const int bufferSize = 2;

void setup(){
  Serial.begin(9600);
 
  Serial.print("Initializing wireless card...");
  Mirf.cePin = 49;
  Mirf.csnPin = 48;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Serial.println("Done");
 
  Serial.print("Setting addresses, payloads and channel...");
  Mirf.setRADDR((byte *)"clnt1");
  Mirf.setTADDR((byte *)"clnt2");
  Mirf.payload = bufferSize;
  Mirf.channel = 80;
  Serial.print("Finishing configuration...");
  Mirf.config();
  Serial.println("Done");
 
}

void loop(){
  Serial.print(".");
 
  if (Mirf.dataReady())
  {
     Mirf.getData(buffer);
     
    delay(50);
   
    for (int i = 0; i < bufferSize; i++)
    {
      Serial.print(buffer[i]);
      Serial.print(",");
    }
    Serial.println();
  }
 
  delay(1000);
}


ATTiny85:
Code: [Select]
#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>


const int bufferSize = 2;
byte buffer[] = {
  'D','S'
};

#define CE  PB3 //ATTiny
#define CSN PB4 //ATTiny

void setup(){
  Mirf.cePin = CE;
  Mirf.csnPin = CSN;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();


  Mirf.setRADDR((byte *)"clnt2");
  Mirf.payload = 2;
  Mirf.channel = 80;
  Mirf.setTADDR((byte *)"clnt1");
  Mirf.config();
}

void loop(){
  Mirf.send(buffer);
  while( Mirf.isSending() )
  {
    delay(1);
  }
  delay(1000);
}


Try swapping around the MOSI and MISO on the ATTiny if it doesn't work the first time. Also, Mirf.getStatus() should give 14 if it's wired correctly and no packets were received.

fgasparri

Hi Davste,
I tried everything, even the last code  you posted, and I can't make it work. I've been struggling for weeks with this, no luck so far. I have an Attiny85 acting as the Transmitter, and an Arduino Uno as the receiver.
Did you tried your code with the same configuration (attiny85->tx, Uno->rx) ?
I'm stuck, and is really difficult to debug the attiny portion. I suspect the problem is on the attiny side. If I try making the arduino sending data, and connect a led to the CSN pin, it blinks as if it is transmitting (the expected behavior). If I change the code to make the Attiny transmit (the original code you posted) and connect a led to the CSN pin, the led is always turned on, like the CSN signal is always high.
I've checked the connection hundreds of time, still can't communicate the attiny with the arduino board.
I am using the MIRF85 and SPI85 libraries from this post.
Any help will be appreciated!
Best
Fabio

Davste

#74
Apr 03, 2013, 11:21 am Last Edit: Apr 03, 2013, 11:24 am by Davste Reason: 1

Hi Davste,
I tried everything, even the last code  you posted, and I can't make it work. I've been struggling for weeks with this, no luck so far. I have an Attiny85 acting as the Transmitter, and an Arduino Uno as the receiver.
Did you tried your code with the same configuration (attiny85->tx, Uno->rx) ?
I'm stuck, and is really difficult to debug the attiny portion. I suspect the problem is on the attiny side. If I try making the arduino sending data, and connect a led to the CSN pin, it blinks as if it is transmitting (the expected behavior). If I change the code to make the Attiny transmit (the original code you posted) and connect a led to the CSN pin, the led is always turned on, like the CSN signal is always high.
I've checked the connection hundreds of time, still can't communicate the attiny with the arduino board.
I am using the MIRF85 and SPI85 libraries from this post.
Any help will be appreciated!
Best
Fabio



Join the club. I agree with everything you have said - it is extreemly difficult to debug these things. I've bought another Uno for debugging this project when it was driving me nuts. But you can get creative. Try this:
Note the numbers will be output backwards. If the LED outputs:
5 - 5 - 2 it means 255, and also means you have bad connections.
If it's 4 - 1 it means 14, and everything should be connected correctly.

Code: [Select]
#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <SPI85.h>
#include <Mirf85.h>
#include <nRF24L0185.h>
#include <MirfHardwareSpiDriver85.h>


const int bufferSize = 2;
byte buffer[] = {
 1,25
};

#define CE  PB3 //ATTiny
#define CSN PB4 //ATTiny

void setup(){
 Mirf.cePin = CE;
 Mirf.csnPin = CSN;
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();


 Mirf.setRADDR((byte *)"clnt2");
 Mirf.payload = 2;
 Mirf.channel = 80;
 Mirf.setTADDR((byte *)"clnt1");
 Mirf.config();
 
 outputNumber(Mirf.getStatus());
}

void loop(){
 Mirf.send(buffer);
 while( Mirf.isSending() )
 {
   delay(1);
 }
 delay(1000);
 
 delay(1000);

}


void outputDigit(int d)
{
Mirf.csnLow();
for (int i = 0; i < d; i++)
{
Mirf.csnHi();
_delay_ms(200);
Mirf.csnLow();
_delay_ms(200);
}


if (d == 0)
{
for (int i = 0; i < 20; i++)
{
Mirf.csnHi();
_delay_ms(50);
Mirf.csnLow();
_delay_ms(50);
}

}


Mirf.csnHi();
_delay_ms(1500); //End of digit
Mirf.csnLow();
}

void outputNumber(int number)
{
//"Outputs" a number by blinking an LED connected to CSN.
// The number will be output backwards. Ex: 982:
// LED Flashes five seconds.
// LED blinks quickly 2 times.
// LED stays on for two seconds.
// LED blinks quickly 8 times.
// LED stays on for two seconds.
// LED blinks quickly 9 times.


Mirf.csnHi();
_delay_ms(1500); //Start of sequence.

int i = 0;
   do {
       outputDigit(number % 10);
    number /= 10;
    i++;
       
   } while (number != 0);

_delay_ms(1500); //End of sequence.
Mirf.csnHi();

}


Try different channels by the way. In the US, channels above 80 are illegal as far as I know.

Go Up