Hi,
I hope someone would be able to help me. I’m preparing a board which will measure a frequency through FreqCount library and will send some other values to another board through RF433 (Radiohead).
when I run the following code, then it hangs (with or without sensors connected)
if I comment one of the 2 following lines, then the code works for one or the other module. I can’t make these 2 modules working together.
- FreqCount.begin(1000);
- driver.send((uint8_t *)tx_buf, zize);
thanks in advance for your help !!
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include <OneWire.h> // Inclusion de la librairie OneWire
#include <LiquidCrystal.h>
#include <FreqCount.h>
LiquidCrystal lcd(9,7, 11, 8, 4, 3, 2);
const float A = 22.0;
int val = 0;
int reading = 0;
int percentage = 0;
double sum=0;
int count=0;
double Msqm;
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#define DS18B20 0x28 // Adresse 1-Wire du DS18B20
#define BROCHE_ONEWIRE 10 // Broche utilisée pour le bus 1-Wire
//#define LCDPIN A2 /
OneWire ds(BROCHE_ONEWIRE); // Création de l'objet OneWire ds
RH_ASK driver;
//PUSHBUTTONS
const int buttonPin1 = 6;
int buttonState1 = 0;
int LCDPIN = A2;
int increment;
String SerialDegC, infos;
char SerialDegree[3];
char valuetoprint[20];
unsigned long time1 = 0;
unsigned long time2 = 60000 ;
struct dataStruct{
float temp_ciel ;
float temp_ambient;
float humid;
float temp;
unsigned long counter;
}myData;
byte tx_buf[sizeof(myData)] = {0};
// Fonction récupérant la température depuis le DS18B20
// Retourne true si tout va bien, ou false en cas d'erreur
boolean getTemperature(float *temp){
byte data[9], addr[8];
// data : Données lues depuis le scratchpad
// addr : adresse du module 1-Wire détecté
if (!ds.search(addr)) { // Recherche un module 1-Wire
ds.reset_search(); // Réinitialise la recherche de module
return false; // Retourne une erreur
}
if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
if (addr[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
return false; // Si ce n'est pas le cas on retourne une erreur
ds.reset(); // On reset le bus 1-Wire
ds.select(addr); // On sélectionne le DS18B20
ds.write(0x44, 1); // On lance une prise de mesure de température
delay(800); // Et on attend la fin de la mesure
ds.reset(); // On reset le bus 1-Wire
ds.select(addr); // On sélectionne le DS18B20
ds.write(0xBE); // On envoie une demande de lecture du scratchpad
for (byte i = 0; i < 9; i++) // On lit le scratchpad
data[i] = ds.read(); // Et on stock les octets reçus
// Calcul de la température en degré Celsius
*temp = ((data[1] << 8) | data[0]) * 0.0625;
// Pas d'erreur
return true;
}
void setup() {
pinMode(buttonPin1,INPUT_PULLUP );
pinMode(LCDPIN, OUTPUT);
digitalWrite(LCDPIN, HIGH);
increment = 0;
SerialDegC += char(223); // Setup a Degrees C Serial symbol
SerialDegC += "C";
SerialDegC.toCharArray(SerialDegree,3);
Serial.begin(9600);
mlx.begin();
if (!driver.init())
Serial.println("init failed");
FreqCount.begin(1000);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("WINCH INTERFACE");
lcd.setCursor(0, 1);
lcd.print("V1.0 2016");
delay(3000);
double sum=0;
int count=0;
}
void loop() {
time1 = millis();
if (time1 > time2) {
digitalWrite(LCDPIN, LOW);
}
if (FreqCount.available()) {
unsigned long count = FreqCount.read();
Serial.println(count);
}
float temp;
// Lit la température ambiante à ~1Hz
if(getTemperature(&temp)) {
// Affiche la température
Serial.print("Temperature : ");
Serial.print(temp);
Serial.write(176); // caractère °
Serial.write('C');
Serial.println();
myData.temp = temp;
}
//MLX 6014
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.write(176); Serial.write('C');Serial.println();
myData.temp_ciel=mlx.readObjectTempC();
myData.temp_ambient = mlx.readAmbientTempC();
//MLX 6014
float humivalue = analogRead(A0);
// myData.humid=(1/humivalue)*3072;
myData.humid = map(humivalue, 0, 1024, 100, 0);
Serial.println(myData.humid);
buttonState1 = digitalRead(buttonPin1);
char convert[11];
if (buttonState1 == LOW) {
increment++;
time2 = millis() + 59000;
delay(1000);
digitalWrite(LCDPIN, HIGH);
lcd.clear();
switch (increment) {
case 1:
lcd.setCursor(0, 0);
lcd.print("Temp Sonde");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// lcd.print(myData.temp);
dtostrf(myData.temp, 5, 2, convert);
sprintf(valuetoprint, "%s%s", convert, SerialDegree);
lcd.print(valuetoprint);
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Temp Ambiente");
lcd.setCursor(0, 1);
dtostrf(myData.temp_ambient, 5, 2, convert);
sprintf(valuetoprint, "%s%s", convert, SerialDegree);
lcd.print(valuetoprint);
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("Temp Ciel");
lcd.setCursor(0, 1);
dtostrf(myData.temp_ciel, 5, 2, convert);
sprintf(valuetoprint, "%s%s", convert, SerialDegree);
lcd.print(valuetoprint);
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("SQM-60sec/mesure");
lcd.setCursor(0, 1);
dtostrf(Msqm, 5, 2, convert);
sprintf(valuetoprint, "%s", convert);
lcd.print(valuetoprint);
break;
default:
increment = 0;
lcd.setCursor(0, 0);
lcd.print("Cliquez pour");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
infos = "plus d infos";
infos.toCharArray(valuetoprint,20);
lcd.print(valuetoprint);
break;
}
}
memcpy(tx_buf, &myData, sizeof(myData) );
byte zize=sizeof(myData);
//driver.init();
driver.send((uint8_t *)tx_buf, zize);
driver.waitPacketSent(500);
myData.counter++;
delay(600);
}