Adafruit nRF8001 library update
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
I've posted a set of fixes here:
http://forum.pjrc.com/threads/27069-Ada ... #post58371
All three libraries need to be updated, plus a couple more files if using Teensy 3.1. I know that's a lot of stuff to manually update, so please only give this a try if you're good with manually replacing files in the proper locations.
I have personally tested nRF8001 and SD card access together on Arduino Uno, Teensy 2.0 and Teensy 3.1. All 3 appear to now to be working, but of course I've only done limited testing so far with a modified copy of the test Lyton posted.
Please let me know how these fixes work for you?
http://forum.pjrc.com/threads/27069-Ada ... #post58371
All three libraries need to be updated, plus a couple more files if using Teensy 3.1. I know that's a lot of stuff to manually update, so please only give this a try if you're good with manually replacing files in the proper locations.
I have personally tested nRF8001 and SD card access together on Arduino Uno, Teensy 2.0 and Teensy 3.1. All 3 appear to now to be working, but of course I've only done limited testing so far with a modified copy of the test Lyton posted.
Please let me know how these fixes work for you?
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
Has anyone tried this, and on which boards?
Today, one person (other than me) has confirmed it on Teensy 3.1. I tested on Teensy 2.0 & 3.1 and also Arduino Uno. So far, no reports from anyone using other Arduino boards....
Today, one person (other than me) has confirmed it on Teensy 3.1. I tested on Teensy 2.0 & 3.1 and also Arduino Uno. So far, no reports from anyone using other Arduino boards....
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Adafruit nRF8001 library update
Paul - Can you post your test sketch?
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
Code: Select all
// http://forum.pjrc.com/threads/27069-Adafruit_nrf8001-and-SDFat-problem-on-teensy-3-1
#include <SPI.h>
#include <Adafruit_BLE_UART.h>
#include <SD.h>
#define SDCARD_CS 4
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RST 9
#if defined(__AVR__) && defined(TEENSYDUINO)
#define ADAFRUITBLE_RDY 5 // pin 5 on Teensy 2.0
#else
#define ADAFRUITBLE_RDY 2 // pin 2 on Arduino Uno & Teensy 3.1
#endif
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
/**************************************************************************/
/*!
This function is called whenever select ACI events happen
*/
/**************************************************************************/
void aciCallback(aci_evt_opcode_t event)
{
switch(event)
{
case ACI_EVT_DEVICE_STARTED:
Serial.println(F("Advertising started"));
break;
case ACI_EVT_CONNECTED:
Serial.println(F("Connected!"));
break;
case ACI_EVT_DISCONNECTED:
Serial.println(F("Disconnected or advertising timed out"));
break;
default:
break;
}
}
/**************************************************************************/
/*!
This function is called whenever data arrives on the RX channel
*/
/**************************************************************************/
void rxCallback(uint8_t *buffer, uint8_t len)
{
Serial.print(F("Received "));
Serial.print(len);
Serial.print(F(" bytes: "));
for(int i=0; i<len; i++)
Serial.print((char)buffer[i]);
Serial.print(F(" ["));
for(int i=0; i<len; i++)
{
Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
}
Serial.println(F(" ]"));
/* Echo the same data back! */
uart.write(buffer, len);
// Triger card read if 'K" is in the buffer.
if (*buffer == 'K' || *buffer == 'k') {
get_sd_card_files();
}
}
/**************************************************************************/
/*!
Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{
// first, bring both chip selects up to logic high
// each library will make the pin an output, but
// this prevents either device from "hearing" the
// communication to the other's initialization.
pinMode(ADAFRUITBLE_RDY, INPUT_PULLUP);
pinMode(SDCARD_CS, INPUT_PULLUP);
pinMode(14, OUTPUT);
digitalWrite(14, LOW); // test LED on pin 14
delay(50);
Serial.begin(9600);
while(!Serial); // Leonardo/Micro should wait for serial init
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));
//SD.begin(SDCARD_CS);
uart.setRXcallback(rxCallback);
uart.setACIcallback(aciCallback);
uart.setDeviceName("NEWNAME"); /* 7 characters max! */
uart.begin();
}
/**************************************************************************/
/*!
Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
void loop()
{
uart.pollACI();
}
void get_sd_card_files()
{
Serial.println(F("Opening SD card to generate list"));
Serial.print("EIMSK = ");
Serial.println(EIMSK);
if (SD.begin(SDCARD_CS)) {
Serial.println(F("SD card is ok :-)"));
//printDirectory(SD.open("/"), 0);
} else {
Serial.println(F("no SD card"));
}
Serial.print("EIMSK = ");
Serial.println(EIMSK);
//Serial.print("SPI.interruptMode = ");
//Serial.println(SPI.interruptMode);
}
void printDirectory(File dir, int numTabs) {
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("**nomorefiles**");
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs+1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Adafruit nRF8001 library update
Works with a Leonardo.
Should I try it with a Due - is the SPI library compatible?
The adafruit version of SD adds some features over the Arduino version, such as the ability to use soft SPI. It also adds a function SD.end(), which allows you to call SD.begin() again (as you do in your test code). Any chance you could apply your patch to the Adafruit version? Or tell me what's different?
https://github.com/adafruit/SD
UPDATE: Also works with a Yun
Should I try it with a Due - is the SPI library compatible?
The adafruit version of SD adds some features over the Arduino version, such as the ability to use soft SPI. It also adds a function SD.end(), which allows you to call SD.begin() again (as you do in your test code). Any chance you could apply your patch to the Adafruit version? Or tell me what's different?
https://github.com/adafruit/SD
UPDATE: Also works with a Yun
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
Sure, give it a try on Due.adafruit_support_rick wrote: Should I try it with a Due - is the SPI library compatible?
But you'll need to update the SD library. The copy I posted is only for Arduino 1.0.6. Arduino has already merged my fix, so you can grab a copy for 1.5.8 from their github. You only need to replace 1 file: Sd2Card.cpp. Just make sure you pull it from the 1.5.x branch, not the master branch. Here's a direct link:
https://github.com/arduino/Arduino/blob ... d2Card.cpp
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
Oh, on second thought, there's probably no point wasting time on testing with Arduino Due. It won't even compile, due to this:
https://github.com/PaulStoffregen/Adafr ... l.cpp#L199
I didn't write that AVR-only, but I did optimize it a bit. The original version is here:
https://github.com/adafruit/Adafruit_nR ... l.cpp#L195
It can't possibly work on non-AVR hardware. Well, except for Teensy 3.x, which has limited AVR emulation. The update needed to test on Teensy 3.1 improves the EIMSK emulation so this library can work. But no such software exists on Arduino Due.
I really like Adafruit and I'm willing to help you guys out with some of these tough SPI compatibility problems, but I'm not going to take on redesigning libraries. That's just way too much work. There's only so many hours in each day!
https://github.com/PaulStoffregen/Adafr ... l.cpp#L199
I didn't write that AVR-only, but I did optimize it a bit. The original version is here:
https://github.com/adafruit/Adafruit_nR ... l.cpp#L195
It can't possibly work on non-AVR hardware. Well, except for Teensy 3.x, which has limited AVR emulation. The update needed to test on Teensy 3.1 improves the EIMSK emulation so this library can work. But no such software exists on Arduino Due.
I really like Adafruit and I'm willing to help you guys out with some of these tough SPI compatibility problems, but I'm not going to take on redesigning libraries. That's just way too much work. There's only so many hours in each day!
- adafruit2
- Posts: 22752
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Adafruit nRF8001 library update
hiya paul! there's really no need to expend effort on this library if you find it difficult! we may make it more processor-neutral at some point but we're also moving to the nrf51822 so it's a balance between "work on a thing people have but is only for Arduino Uno" and "work on a thing that is better over all and in the meantime make sure it isn't Uno only" we are leaning towards the latter.
making portable low-level interrupt-managing code is hard! :)
making portable low-level interrupt-managing code is hard! :)
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Adafruit nRF8001 library update
Yeah, probably not worth redoing the code.
As far as I'm concerned, it's perfect now (well, with these changes) since it works with all the Teensy boards. ;)
As far as I'm concerned, it's perfect now (well, with these changes) since it works with all the Teensy boards. ;)
- arturolaz
- Posts: 22
- Joined: Fri Jun 17, 2011 3:18 pm
Re: Adafruit nRF8001 library update
Hi, maybe someone here can help me with a problem with SPI transactions, here is a post on the PJRC Forum, thanks.
Please be positive and constructive with your questions and comments.