Pages: 1 ... 5 6 [7] 8 9   Go Down
Author Topic: attiny 85, any pointers?/  (Read 17189 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 440
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great project! Tough challenges! Here are some pointers:

http://cosa-arduino.blogspot.se/2013/03/news-virtual-wire-interface.html See fig. 7 ATtiny85 with ultra cheap RF433 transmitter and 1-Wire Digital Thermometer. You can find the transmitter sketch at https://github.com/mikaelpatel/Cosa/blob/master/examples/VWI/CosaVWItempsensor/CosaVWItempsensor.ino and the receiver sketch at https://github.com/mikaelpatel/Cosa/blob/master/examples/VWI/CosaVWItempmonitor/CosaVWItempmonitor.ino

Your project is a great encouragement to port the Cosa NF24L01 driver to ATtiny85. First a USI/SPI driver will be needed.

Cheers!
Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


They are on this thread, look at this post:


Thanks Dave for the links.... still have not gotten it to work "yet"!!!

How do you debug the attiny85 ? I scope both the CSN and MOSI pins... but still nothing on the Arduino UNO side...

Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally got it working... thanks for the sample codes, spi85 and mirf85 libs..

I'm running on channel 0x50 as the scanner shows no traffic at this channel...

I made some modifications to add support for 1Mbps as the default mirf is running on 2Mbps..
*** Do the same for the mirf libraries..

[edit]
I got it working for RF24 as most of my UNO/RPi is running on RF24 here :- https://github.com/stanleyseow/RF24

Changes needed in the mirf / mirf85 codes :-

1. the address is flipped when configure in mirf (no idea why???) :-
  byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0}; will match RF24 :-
      const uint64_t pipes[2] = { 0x7365727631LL, 0xF0F0F0F0E3LL };

2. Default CRC for mirf is 8bit so set the RF24 radio.setCRCLength(RF24_CRC_8) or change mirf85.h line 38 :-
#define mirf_CONFIG ((1<<EN_CRC) | (1<<CRCO) )  // 1 << CRC0 is 16bit/2bytes

3. Default data rate for nRF24L01/mirf is 2Mbps, so set the RF24 radio.setDataRate(RF24_2MBPS)

4. Channels can be confusing, so use 0x50 or whatever in HEX ( 0xnn) when setting the channel for both

5. Enable dynamic payload ( I enable them for all my RF24 receivers ) in mirf :-
  
// Enable dynamic payload in attiny85 mirf
  Mirf.configRegister( FEATURE, 1<<EN_DPL );
  Mirf.configRegister( DYNPD, 1<<DPL_P0 | 1<<DPL_P1 | 1<<DPL_P2 | 1<<DPL_P3 | 1<<DPL_P4 | 1<<DPL_P5 );
    

I made an 6-pin adapter on top of the attiny85 for easy uploading of hex to the attiny85 and I put an LED at Pin2 to blink 3 times during the 1 sec delays when isSending is successful..

Drawing 3.3V power from a breadboard power supply and USBtinyISP as my programmer...




attiny85
Code:
Mirf.rfsetup = 0x06; // RF_SETUP settings :- 0x06 = 1Mbps, max power, 0x0e for 2Mbps, max power

mirf85.cpp
Code:
Nrf24l::Nrf24l(){
cePin = 3;
csnPin = 4;
channel = 40;
payload = 5;
rfsetup = 0x06; // 1Mbps, max power
spi = NULL;
}

void Nrf24l::config()
// Sets the important registers in the MiRF module and powers the module
// in receiving mode
// NB: channel and payload must be set now.
{
    // Set RF channel
configRegister(RF_CH,channel);
    // Set RF_SETUP
configRegister(RF_SETUP,rfsetup);

    // Set length of incoming payload
configRegister(RX_PW_P0, payload);
configRegister(RX_PW_P1, payload);

    // Start receiver
    powerUpRx();
    flushRx();
}


mirf85.h
Code:
/*
* Rate is RF_SETUP, 0x06 is 1Mbps, Max power
*/

uint8_t rfsetup;
« Last Edit: April 10, 2013, 02:18:34 pm by Stanley » Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've compiled all the files, headers and examples and made a github repo for future references :-

https://github.com/stanleyseow/attiny-nRF24L01

Pls let me know if you need me to add examples to the repo...

Anyone searching for attiny nrf24L01 at github should be able to find it...

Logged

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

Spectacular work stanley thanks for the work that you had done to collect everything in one place.

Thanks.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1121
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've compiled all the files, headers and examples and made a github repo for future references :-
Pls let me know if you need me to add examples to the repo...
Thanks for sharing your success.  I think a test example is always a good idea for these, so yes please.  smiley

Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

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

I just got the ATTINY85 from sparkfun, I tried it with the stanley examples that put on github and it works great, at least I have the LED flashing 3 times. Now i need to make the receiver with the Arduino UNO and see what actually receive.
Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some improvement, you could add the TinyDebugSerial to "see" what's going on...

I documented it in my blog for future reference...

http://arduino-for-beginners.blogspot.com/2013/04/added-tinydebugserial-to-attiny85.html

Logged

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

Stanley, sadly i cant work whit TinyDebugSerial becouse i only got an arduino uno and the serial adaptor seems dont work whitout the atmega328.

I make this sketch to test if im getting something, but sadly seems not work.

Code:
[pre][left]

void setup()
{
  Serial.begin(9600);
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
 
  byte RADDR[] = {0xe2, 0xf0, 0xf0, 0xf0, 0xf0};
  Mirf.setRADDR(RADDR);
  
  Mirf.payload = sizeof(unsigned long);
  Mirf.channel = 0x4c;
  Mirf.config();
  
  Serial.println("Listening...");
 
}


int data;


void loop()
{
   if(Mirf.dataReady())
   {Serial.print("Incoming data-....");
    
     Mirf.getData((byte *) &data);
     Serial.println(data);
     delay(100);
    
   }


data=0;

}
[/left][/pre]

Im doing it something wrong? maybe its about the dinamic payload?

here si the tx code

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

  // This address is compatible with my example of rpi-hub or nRF24_Arduino_as_hub
  // at repo https://github.com/stanleyseow/RF24/examples/
 
  byte RADDR[] = {0xe2, 0xf0, 0xf0, 0xf0, 0xf0};
  byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0};
 
  Mirf.payload = sizeof(buffer);
 
  Mirf.channel = 0x4c; // Same as rpi-hub and sendto_hub
  Mirf.rfsetup = 0x06; // 1Mbps, Max power
  Mirf.setRADDR(RADDR); 
  Mirf.setTADDR(TADDR);
  Mirf.config();
 
  // Enable dynamic payload
  Mirf.configRegister( FEATURE, 1<<EN_DPL );
  Mirf.configRegister( DYNPD, 1<<DPL_P0 | 1<<DPL_P1 | 1<<DPL_P2 | 1<<DPL_P3 | 1<<DPL_P4 | 1<<DPL_P5 );
   
}

void loop(){
 
  uint8_t sent = false;
 
  Mirf.send(buffer);
  while( Mirf.isSending() )
  {
    delay(1);
    sent = true; // Sent success
  }

  delay(400);
  if (sent) {   // Blink CE ( pin 2), 3 times
      digitalWrite(3,HIGH); 
      delay(100);
      digitalWrite(3,LOW); 
      delay(100);
      digitalWrite(3,HIGH);
      delay(100);
      digitalWrite(3,LOW); 
      delay(100);
      digitalWrite(3,HIGH);
      delay(100);
      digitalWrite(3,LOW); 
      delay(100);
  } else {
      digitalWrite(3,LOW);  // Sent not success, OFF the LED
      delay(600);
  }

}
« Last Edit: April 25, 2013, 04:36:30 pm by raedon » Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Stanley, sadly i cant work whit TinyDebugSerial becouse i only got an arduino uno and the serial adaptor seems dont work whitout the atmega328.


TinyDebugSerial is for attiny "only" not atmega... if you are using atmega328, Digital pin 0 & 1 is hardware serial....

Not sure I understand yr issue, can you post yr error messages here ??

*** again, attiny can take 5V Vcc but the nRF24L01 Vcc can only take a max voltage of 3.3-3.7V

How are you setting up yr components ?
attiny - nRF  <==2.4Ghz==> nRF - Arduino UNO ???


Logged

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

Quote
Stanley, sadly i cant work whit TinyDebugSerial becouse i only got an arduino uno and the serial adaptor seems dont work whitout the atmega328.

How are you setting up yr components ?
attiny - nRF  <==2.4Ghz==> nRF - Arduino UNO ???

Exactly that way, what I meant is that I have an Arduino UNO to use as serial adapter. what I do is connect the pin 2 of the ATtiny, with the RX pin of the UNO without the M328 chip.

So I wanted to make a receiver to see if it really is sending something. So far, nothing
Logged

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

Actually it should be to pin 1 TX on Arduino.

Se SadamHu's picture here, reply #18

http://arduino.cc/forum/index.php?PHPSESSID=713cf311e2c5b068668674c1fdf48794&topic=161271.15
« Last Edit: April 26, 2013, 08:51:26 am by Erni » Logged

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

Thank u Erni, now its working good, i got this ouput:

Code:
RF_CH :4C
RF_SETUP :110
TX_ADDR :E3F0F0F0F0
RX_ADDR :E2F0F0F0F0
üÿSent :E3,0001,000000
üSent :E3,0001,000001
üSent :E3,0001,000002

Now i need to meke the reciever (on arduino UNO).
Any hint on how i need to proceed?
Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 193
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now i need to meke the reciever (on arduino UNO).
Any hint on how i need to proceed?

This code below should compile and work without any modification... install the Rf24 libs first...

https://github.com/stanleyseow/RF24/tree/master/examples/nRF24_Arduino_as_hub

Channel : 76 = 0x4c
Rate : 1Mbps
CRC : 16bit
Dynamic Payload enable
Logged

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

Stanly thanks u so much for ur support, now i got it working!!!
Logged

Pages: 1 ... 5 6 [7] 8 9   Go Up
Jump to: