I have been experience problems trying to communicate an ATtiny85 with a Adafruit nRF8001 BLE unit. Specifically what I want to do is to transmit some data I'm measuring with the ATtiny to a Cell Phone. If the data falls into a centain range, it transmits a one, else transmits a zero. I'm using the Bluefruit LE Android App on my Cell Phone for this. So first I established communication between an Arduino UNO and a Cell Phone, through an Adafruit nRF8001 BLE unit without problems. But when I'm trying to do the same with the ATtiny, it doesn't work. I check the output signals from the ATtiny that goes to the Adafruit BLE unit with an oscilloscope, and it seem everything it's ok with that. I'm programing the ATtiny using the Arduino IDE. The schematic of my design it is attached.
What do I'm to do is measuring a signal through PIN 2 (PB3) using it as a ADC input. This signal has been amplified and filtered with a very low frequency high pass RC filter, so in order to charge the Capacitor as fast as possible, I use the PIN 3 (PB4) as an output for charge this capacitor. On my first programs I was using the PIN 1 (PB5) as chip Select, but it seems PB5 it's useless when you use Arduino IDE for programing an ATtiny, So I connect REQ (on the Adafruit nRF8001 BLE) directly to GND, which it keeps this PIN at LOW level all the time. Same with RESET pin (on the Adafruit). I prove using active low logic and active high logic for the RESET pin with same results.
The code is very simple, here is it :
Code: Select all
/*
* Aired - SRI board - INO file with SRI algorithm and previous communication algorithm for BLE_nRF8001
*/
const byte sensorPIN = A3;
const byte phiPIN = PB4;
const byte MISO = PB1;
const byte MOSI = PB0;
const byte SCK = PB2;
const int ThresSup = 650;
const int ThresInf = 350;
const int alarm = 50; //alarma se activa a los 5 seg = 50 *interval
const int interval = 100; //sensor sample rate in ms
int sensorVal;
int Alarma;
float timer_1;
void setup() {
analogReference(DEFAULT);//Configures the reference voltage used for analog input (DEFAULT = 5V)
pinMode(sensorPIN, INPUT);
pinMode(phiPIN, OUTPUT);
pinMode(MISO, INPUT);
pinMode(MOSI, OUTPUT);
pinMode(SCK, OUTPUT);
//Phi enable for 1000 ms
digitalWrite(phiPIN, HIGH);
delay(1000);
digitalWrite(phiPIN, LOW);
// se inicializa el contador del timmer
timer_1 = 0;
//se inicia la alarma como LOW (estado normal)
Alarma = 0;
digitalWrite(SCK, LOW);
}
void loop() {
sensorVal = analogRead(sensorPIN);
if ((sensorVal <= ThresSup) && (sensorVal >= ThresInf)) { //si estoy en la franja
if (timer_1 >= (alarm * interval)) {//si además han pasado 5 segundos dentro de la franja
Alarma = 1;
}
}
else {//si no estoy dentro de la franja
timer_1 = 0;
Alarma = 0;
}
//shiftOut( data_PIN_out, serial_Clock, Most or Least significant Bit first, Data );
shiftOut(MOSI, SCK, MSBFIRST, Alarma);
delay(100);
timer_1 = timer_1 + interval;
}