Expected constructor, destructor or type conversion before '=' token

Hi,

I am trying to get a home made Arduino board to read a DS18B20 temperature sensor and send the result via an NRF24l01 wireless link (using code from another working sketch)to another homemade board connected to my PC. I had it working with a DHT11 but wanted a sensor that could sense the temperature more accurately than I could sense it myself by just guessing :roll_eyes:

Anyway, I have had the DallasTemperature library example sketches working fine on the board but when I try to adapt it to include the NRF wireless I get trouble. Now I have it narrowed down to a single error which says

error: expected constructor, destructor, or type conversion before ‘=’ token

it points to line 57 which is the last line of this;

float myData[3];
myData[0]=0.0;

The whole sketch is here;

//
//   FILE:  dht11_NRF24_test.pde
// PURPOSE: DS18B20 transmit over NRF24 sketch for Arduino

 //Indicator LED
  int led = 4;
  
// NODE SPECIFIC SETTINGS
#define NODE_ID 0//must be 0-15. Also used for retransmit delay
#define TARGET_PIPE PIPE_1

// ***********************************
// Radio pipe addresses for the nodes to communicate.
#define PIPE_0 0xF0F0F0F000LL
#define PIPE_1 0xF0F0F0F001LL
#define PIPE_2 0xF0F0F0F002LL
#define PIPE_3 0xF0F0F0F003LL
#define PIPE_4 0xF0F0F0F004LL
#define PIPE_5 0xF0F0F0F005LL

// *************************************
//RF24 includes
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);

//**************************************************
//DS18B20 includes and defines
#include <OneWire.h>
#include <DallasTemperature.h>

void printAddress(DeviceAddress deviceAddress);
void printTemperature(DeviceAddress deviceAddress);
void printResolution(DeviceAddress deviceAddress);
void printData(DeviceAddress deviceAddress);

// Data wire is plugged into port D7 on the Arduino
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

// Array to hold temperature data
//[NODE_ID, Inside thermom, outside thermom]
  float myData[3];
  myData[0]=0.0;

 // function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}

// ********************************************

void setup()
{
  pinMode(led, OUTPUT); 
  pinMode(ONE_WIRE_BUS, INPUT);
  Serial.begin(57600);
  Serial.println("Sensor Node Firmware v2");
  Serial.print("Node ID: ");
  Serial.println(NODE_ID);
  Serial.print("Target Pipe: ");
  //Serial.println(TARGET_PIPE);
 
  // ***************************************  
 
  // Setup and configure rf radio
  radio.begin();
  radio.openWritingPipe(TARGET_PIPE);
 
  // Set ARD Auto Retransmit Delay to Node ID so all different
  // This prevents restransmissions clashing
  radio.setRetries(NODE_ID,5);
  radio.printDetails();

  // *************************************************
 
 //  Set up DS18B20s
  // Start up the library
  sensors.begin();

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
 // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  // 
  // method 1: by index
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); 
 
    // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();

  // set the resolution to 9 bit
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(outsideThermometer), DEC); 
  Serial.println();
  
}



void loop()
{
// ***********************************************
// Read DS18B20(s) 
 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  // print the device information
  printData(insideThermometer);
  myData[1] = sensors.getTempC(insideThermometer);
  printData(outsideThermometer);  
  myData[2] = sensors.getTempC(outsideThermometer);

// send the results over the radio

  bool ok = radio.write( &myData, sizeof(myData) );
  if (ok)
  {    printf("ok...");
      Serial.print("Sent data ");
    
  }
  else
  {    printf("failed.\n\r");
       Serial.println("Radio send failed.");
  }
  //Flash LED at end of cycle 
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(9000);

}
//
// END OF FILE
//

I really want to set myData[0] to NODE_ID which is a #define to value 0 (and is also used for something else so NODE_ID can’t be a float) but obviously that is not a float so for testing purposes I changed it to 0.0 which I think should be.

Any ideas where I am going wrong would be gratefully received. I have looked for type conversions in Beginning Arduino Programming and C++ How to Program but couldn’t find anything on how you do that.

Thanks

Your assignment is in the global scope - you cannot assign like that in the global scope. Instead, you should use:

float myData[3] = {0.0};

Majenko,

Great! That fixed it. Also works for NODE_ID.

Thanks for the quick response - much appreciated

Regards