Comments (12)
I have got a little closer. I have pulled up chip select pin with (digitalWrite(BLE_REQ_PIN), HIGH) before every SD function, and it looks okay now. I guess in the library it is left out.
from arduino-bleperipheral.
@szotyi007 please share your full sketch and pins used etc.
from arduino-bleperipheral.
please find my code below (I have made it simple to point out the problem):
#include <SPI.h>
#include <SD.h>
#include <stdint.h>
#include <BLEPeripheral.h>
#define BLE_REQ 6
#define BLE_RDY 5
#define BLE_RST 4
BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
BLEService uartService = BLEService("713d0000503e4c75ba943148f18d941e");
BLECharacteristic txCharacteristic = BLECharacteristic("713d0002503e4c75ba943148f18d941e", BLENotify, 20);
BLECharacteristic rxCharacteristic = BLECharacteristic("713d0003503e4c75ba943148f18d941e", BLEWriteWithoutResponse, 20);
BLECentral central = blePeripheral.central();
boolean display_connected = false;
void setup() {
setup_ble();
// digitalWrite(6, HIGH); must be used for working..
if (!SD.begin(8)) {
Serial.println("initialization failed!");
}
File file = SD.open("/");
file.close();
}
void loop() {
if (display_connected == false) {
central = blePeripheral.central();
if (central) {
display_connected = true;
Serial.print("Connected to central: ");
Serial.println(central.address());
}
}
if (display_connected && central.connected()) {
if (rxCharacteristic.written()) {
unsigned char len = rxCharacteristic.valueLength();
const unsigned char *val = rxCharacteristic.value();
unsigned char i = 0;
while (i < len) {
Serial.write(val[i++]);
}
}
if (txCharacteristic.canNotify()) {
txCharacteristic.setValue((const unsigned char *)"12345", 21);
}
}
if (display_connected == true && central.connected() == false ) {
display_connected = false;
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
void setup_ble() {
blePeripheral.setLocalName("customBle");
blePeripheral.setAdvertisedServiceUuid(uartService.uuid());
blePeripheral.addAttribute(uartService);
blePeripheral.addAttribute(rxCharacteristic);
blePeripheral.addAttribute(txCharacteristic);
blePeripheral.begin();
Serial.println(F("BLE UART Peripheral"));
}
from arduino-bleperipheral.
@szotyi007 what hardware are you using?
from arduino-bleperipheral.
Arduino Due, with MOLEX 502774-0891 SD socket, Readbearlab shield V 2.1
from arduino-bleperipheral.
Have you find the cause of the bug? I have found this:
BLE Shield communicates with Arduino through the ACI (Application Controller Interface). The ACI is similar to SPI but does not actually work as SPI. SPI is consist of MOSI, MISO, SCK and SS, whereas ACI is consist of MOSI, MISO, SCK, REQN and RDYN.
Since BLE Shield may receive data anytime even not selected by SPI master (Arduino), so the SS line is not needed.
In ACI,data exchanged still through MOSI and MISO, and SCK provides the clock generated by master.
When master wants to request data from BLE Shield, it puts the REQN to low until RDYN line is put to low by BLE Shield, and then master generates the clock to read out the data. After reading out the data, master will release the REQN and BLE Shield release the RDYN, put them to high.
If BLE Shield has data to transmit to master, it will put the RDYN to low to indicate master, even though master havn't requested data and REQN is idle. If master detectes a low level condition on RDYN, it will put REQN to low and generate the clock to read out the data.After reading out the data, both REQN and RDYN will be put to high.Note that REQN is controlled by master while RDYN is controlled by BLE Shield.
But then, how can I use another SPI device with the BLE shield in the same time?
from arduino-bleperipheral.
@szotyi007 I haven't had time to set this up locally, it would be much easier if you could find a way to reproduce without needing an SD card shield.
Could you please try using a different pin instead of 4 (or 10) for reset?
The lower level nRF8001 SDK already pulls REQ high after each SPI transaction: https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/utility/hal_aci_tl.cpp#L209-L212
I'm wondering if something in the SPI or SD card library is changing pin 4 or 6, and possibly reseting the nRF8001.
from arduino-bleperipheral.
Hi!
Thanks for your email.
I have just left it, i have changed the module to the ble nano..
Thanks again!
Zsolt
On Sun, Mar 6, 2016 at 9:26 PM, Sandeep Mistry [email protected]
wrote:
@szotyi007 https://github.com/szotyi007 I haven't had time to set this
up locally, it would be much easier if you could find a way to reproduce
without needing an SD card shield.Could you please try using a different pin instead of 4 (or 10) for reset?
The lower level nRF8001 SDK already pulls REQ high after each SPI
transaction:
https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/utility/hal_aci_tl.cpp#L209-L212I'm wondering if something in the SPI or SD card library is changing pin 4
or 6, and possibly reseting the nRF8001.—
Reply to this email directly or view it on GitHub
#56 (comment)
.
from arduino-bleperipheral.
@szotyi007 ok, I'll close this for now. We can re-open if you or someone else has time to investigate my suggestion on the Due.
from arduino-bleperipheral.
Ok, no problem. Thanks again!
from arduino-bleperipheral.
@szotyi007
Hi, I'm using Redbearlabs BLE Nano. The code which you have shared with SD library is not compiling for BLE Nano. any idea? or do have any other code which library compatible with BLE nano library? I want to save data from BLE Nano to SD card in my application.
from arduino-bleperipheral.
Hi,
I have posted the code, because it was not working properly :) At the time I was using the ble shield, and it compiled.
I have tried now with nano, I also get a lot of error by compiling. I am not sure, how much time to fix everything. What I do is that I use the nano only for "gateway" between my ipad and the "main processor". I use a teensy 3.6 with built-in micro sd card slot and communicate with ble nano over general ttl serial. If the nano receives data from ipad (via bluetooth), it forwards the data to teensy (over serial) and do nothing else, and I actually parse data on the teensy. If I need to send information to ipad then I send it from teensy to nano (over serial) and the nano "forwards" to ipad.
A simple version of my code for ble nano:
#include <stdint.h>
#include <SPI.h>
#include <BLEPeripheral.h>
#define BLE_REQ 9
#define BLE_RDY 8
#define BLE_RST 10
BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
BLEService uartService = BLEService("713d0000503e4c75ba943148f18d941e");
BLECharacteristic txCharacteristic = BLECharacteristic("713d0002503e4c75ba943148f18d941e", BLENotify, 20);
BLECharacteristic rxCharacteristic = BLECharacteristic("713d0003503e4c75ba943148f18d941e", BLEWriteWithoutResponse, 20);
BLECentral central = blePeripheral.central();
char buffer[21];
int buffer_counter = 0;
unsigned long buffer_lastmillis = 0;
boolean display_connected = false;
void setup() {
Serial.begin(38400); // does not work properly with higher baundrate
pinMode(13, OUTPUT);
blePeripheral.setLocalName("testName");
blePeripheral.setAdvertisedServiceUuid(uartService.uuid());
blePeripheral.addAttribute(uartService);
blePeripheral.addAttribute(rxCharacteristic);
blePeripheral.addAttribute(txCharacteristic);
blePeripheral.begin();
Serial.println("GNSS BlE starts");
}
unsigned long counter = 0;
unsigned long lastmillis = 0;
void loop() {
//Serial.println("lol");
if (millis() - lastmillis > 1000) {
digitalWrite(13, !digitalRead(13));
lastmillis = millis();
}
central = blePeripheral.central();
if (display_connected == false) {
if (central) {
display_connected = true;
Serial.print("Connected to central: ");
Serial.println(central.address());
}
}
if (display_connected && central.connected()) {
if (rxCharacteristic.written()) {
unsigned char len = rxCharacteristic.valueLength();
const unsigned char *val = rxCharacteristic.value();
unsigned char i = 0;
while (i < len) {Serial.write(val[i++]);}
//Serial.println("");
}
if (txCharacteristic.canNotify()) {
// txCharacteristic.setValue((const unsigned char *)"test", 1);
}
}
if (display_connected == true && central.connected() == false ) {
display_connected = false;
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
read_serial();
}
void read_serial() {
if (Serial.available()) {
for ( int i = 0; i < sizeof(buffer); i++) buffer[i] = (char)0;
buffer_counter = 0;
unsigned long buffer_lastmillis = millis();
while (Serial.available() || millis() - buffer_lastmillis < 20) {
if (Serial.available()) {
char readed_char = Serial.read();
// Serial.write(readed_char);
buffer[buffer_counter] = readed_char;
buffer_counter++;
buffer_lastmillis = millis();
if (buffer_counter == 20) {
while (!txCharacteristic.canNotify()) { // must be modified for timout
blePeripheral.connected();
//delay(20);
}
txCharacteristic.setValue((const unsigned char *)buffer, 20);
for ( int i = 0; i < sizeof(buffer); i++) buffer[i] = (char)0;
buffer_counter = 0;
}
}
}
if (buffer_counter > 0) {
while (!txCharacteristic.canNotify()) { // must be modified for timout
blePeripheral.connected();
}
txCharacteristic.setValue((const unsigned char *)buffer, 20);
}
}
}
The main reason I have choose this solution because I have to send a lot of data from teensy to iPad, and the BLE is quit slow, and I did not want my main processor to waste time and resources to send the data to my ipad. So i just send all data from teensy to nano, and it buffers and splits the data to 20 bytes packets, and send the packets to ipad as the speed allows. As I remember I had to modify the core serial file to change the buffer size of the incoming serial to not loose any bytes.
from arduino-bleperipheral.
Related Issues (20)
- Can't detect remote devices
- NRF5: CCCDs aren't persisted for bonded peers
- How to set service name ? HOT 1
- ANCS Implementation canWrite is false
- Speed / baudrate of the BLE connection?
- Numpad key codes, anyone?
- How to send more than 20bytes in each transaction with bleSerial.write()?
- Olimexino-nano + Olimexino-nano-ble freezes after begin()
- Why is my BLE Service not appearing after a successful flash? HOT 2
- [Question] Sending long string BLECharacteristic
- Abandoned project?
- nrf52840 HOT 4
- Freeze on blePeripheral.begin(); HOT 7
- BLE Scan
- softdevice_sys_evt_handler_set()
- RFDuino using BLEPerfipheralObserver to scan for iBeacons - Issue HOT 2
- Update iBeacon broadcast packet after starting
- Setting chip to idle state in between measurements
- nRF52832 Supported?
- UART Rx hangs after a few seconds when BLEPeripheral.begin(); is called on nRF51802
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-bleperipheral.