Notifications
Clear all

BME/BMP 280

42 Posts
4 Users
0 Likes
10.7 K Views
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

   
Quote
Topic Tags
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

How about wrapping up all your information into a structure, and sending the complete object via the nrf24l01, which works pretty well?

 


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Where do I find the full documentation for using "structure"? Do they work like "record" in Turbo Pascal or like an object in Java?


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

You just send it over as a normal class/struct in your write function.

Here is the reference documentation I found a while back: NRF24L01

I'll dig up an example I was going to post for someone else...


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

What has been nagging me is the allocation or reservation of memory in the receiver sketch for the 16 bytes required by the bme280data object. This is where I think I am going wrong.

But returning to the struct object, I have found two methods of declaration that appear to be the same, OK let's just say they both work in practice.

This is the first method:

struct Message{
  float temperature;
  float pressure;
  float altitude;
  float humidity;  
  };

Message bme280data; // declare the message object

And this is the second:

struct Message{
  float temperature;
  float pressure;
  float altitude;
  float humidity;  
  }bme280data;

I don't know if one method has any advantages or disadvantages over the other.

As for memory allocation, I assumed that the following line in the receiver sketch

    radio.read(&bme280data, sizeof(bme280data));

took the 16 received bytes and stored them in memory starting at the address referenced by bme280data. I guess I will have to take a look at the read() function in the RF24 library to find out exactly what it is doing.

The other option I was considering was to create a 16 byte char array to accept the incoming data and then writing the array directly to &bme280data.

As for the checksum, I could use the 16 bytes directly in an XOR routine and add the result to the struct object.

struct Message{
  float temperature;
  float pressure;
  float altitude;
  float humidity;
  byte checksum;
  }bme280data;

   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Happy to help... what error messages did you encounter?


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  
Posted by: @frogandtoad

@pugwash

Happy to help... what error messages did you encounter?

None, I am getting run time errors!!

The receiver is printing empty floats e.g.

0.00
0.00
0.00
0.00


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Your declaration looks incorrect... Please try the following "Type Definition":

typedef struct Message{
  float temperature;
  float pressure;
  float altitude;
  float humidity;  
  } bme280data;

bme280data MyObject;

void setup() {
  Serial.begin(9600);
  
  MyObject.temperature = 1.011f;

 Etc...


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Just saw that you're also using the byte data type instead of the uint64_t data type for the address... try the correct data type and see if that makes any difference.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  
Posted by: @frogandtoad

@pugwash

Just saw that you're also using the byte data type instead of the uint64_t data type for the address... try the correct data type and see if that makes any difference.

where exactly do you mean?

const uint64_t address = 01;     //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.

No change!! Still getting 0.00 floats on the serial monitor!

I have changed the above, where else do I need to change the data types?


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

Here are the current .ino files as they stand!

 

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Ok, let me have a look and see if there is anything obvious.

 


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

The odd thing is that the following code in the receiver sketch

    Serial.println(myObject.temperature);
    Serial.println(myObject.pressure);
    Serial.println(myObject.altitude);
    Serial.println(myObject.humidity);
    Serial.println(sizeof(myObject));

is showing 

0.00
0.00
0.00
0.00
16

conclusion, length of 16 bytes is correct, but the data is not being passed to the object


   
ReplyQuote
Page 1 / 3