I'm trying to build an arduino-based plant hatcher for my garden.
It consists of a atmega 328P which sends temperature readings over the nrf24l01 module to my arduino yun. Until now i just read the values with Serial.print() on my arduino yun. My next step was to include the bridge library to start a process in which a python script posts the values to a sqlite 3 database. And now it won't work anymore.
I think it may have something to do with the spi communication of the nrf24l01 but i am not sure.
I hope somebody can help me
Here is the code! It works fine without Bridge.begin() But as soon as I include it it won't work!
#include <Bridge.h>
#include <FileIO.h>
#include <Process.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached
RF24 radio(8,0);
// Network uses that radio
RF24Network network(radio);
void postData();
int sleepDelay = 30000;
// Channel of our node
const uint16_t channel = 90;
// Address of our node
const uint16_t this_node = 0;
const uint16_t other_node = 1;
// Structure of our payload
struct payload_t
{
float tempC;
float hum;
long Vcc;
int moisture; // 4 bytes
};
long NodeVcc;
float NodeTempC;
float NodeHum;
int NodeMoist;
String Voltage, Temperature, Humidity, Moisture;
void setup() {
//Bridge.begin();
delay(3000);
Serial.begin(57600);
SPI.begin();
// Radio setup
radio.begin();
network.begin(channel, this_node);
radio.setDataRate( RF24_2MBPS );
radio.setPALevel( RF24_PA_MAX );
attachInterrupt(0, postData, RISING);
}
void loop() {
network.update();
// Is there anything ready for us?
while ( network.available() ){
// If so, grab it and print it out
getRadioData();
}
}
void postData(){
Serial.println();
Serial.println(millis());
Serial.println();
Process p;
p.begin("/usr/bin/python");
p.addParameter("/mnt/sda1/lookup_garduino.py");
p.addParameter(Humidity);
p.addParameter(Temperature);
p.addParameter(Voltage);
p.addParameter(Moisture);
p.run();
char result = p.read();
if(result == '1') {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
}
Serial.print("Humidity: ");
Serial.print(NodeHum);
Serial.println("%");
Serial.print("T: ");
Serial.print(NodeTempC);
Serial.println(" °C ");
Serial.print(NodeVcc);
Serial.println(" mV");
Serial.println(NodeMoist);
Serial.println();
Serial.println(millis());
Serial.println();
}
void getRadioData(){
RF24NetworkHeader header;
payload_t payload;
bool done = false;
while (!done){
done = network.read(header,&payload,sizeof(payload));
NodeVcc = payload.Vcc;
NodeTempC = payload.tempC;
NodeHum = payload.hum;
NodeMoist = payload.moisture;
}
Voltage = (String)NodeVcc;
Temperature = (String)NodeTempC;
Humidity = (String)NodeHum;
Moisture = (String)NodeMoist;
}
External Interrupts: 3 (interrupt 0), 2 (interrupt 1), 0 (interrupt 2), 1 (interrupt 3) and 7 (interrupt 4). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details. Is not recommended to use pins 0 and 1 as interrupts because they are the also the hardware serial port used to talk with the Linux processor. Pin 7 is connected to the AR9331 processor and it may be used as handshake signal in future. Is recommended to be careful of possible conflicts if you intend to use it as interrupt
Try shifting this to a different pin and check if that works.
first of all thanks for the hint
But unfortunately it didn't solve my problem! I am now using pin 9 as CS for the nRF24L01+ and attached the interrupt to pin 2. So it is interrupt 1 on the yun I think
So far, so good. But once I include Bridge.begin() it doesn't work and the TX LED on the yun is lightning up constantly!
Maybe you know what I can try next
The module works fine on the Yun but I can't tell you much more about it since I don't use the bridge I use a custom application on the linux side to receive serial messages from the sketch when a message is received.
Hey,
Would be great to know how to communicate between linux and a sketch in a different way Which kind of application do you use? Some kind of a python script?
I use a ruby script on the client side to receive the messages and simply write them in my sketch using Serial1 which is the hardware uart connected to the Atheros chip.
This work really great if you want more control over the communication, If you do this there is just one caveat to be aware of: since this serial port is connected physically to the linux part of the board it will receive the boot messages but can also send message which will be interpreted as keypresses.
This sound scary but it is really not, you can't brick your Tun that way (but it can appear bricked), look here if you want more about this: Can't access my yun anymore - Arduino Yún - Arduino Forum
There is another thread linked in the one I linked where people managed to have firmata working on the Yun so you might get some working python example if you want to use it.
Hi Christoph,
I tried connecting nRF24L01+ to Yun and works perfectly fine. (The transmitter is Arduino Uno & nRF24L01+ and receiver is Arduino Yun & nRF24L01+)
I started the bridge and used to Console to print out connection response from transmitter. I get response back in 4 msec (to and back).
So Yun does work when bridge is running.
I used the ICSP header on Yun to derive MISO, MOSI and SCK. I connected CE to pin 8 and CSN to pin 10, modified the RF24 radio object accordingly, compiled and uploaded the code to Yun and it worked.
Also note that I have powered the Yun through Micro USB charger (and not from Computer's USB connection). The Ground for nRF24L01+ is derived from ICSP Header and 3.3 V is derived from the 3.3V supply of Yun.