If I want to use code from c that users 123.456/-654.321 in GCB there's pic code to do it. ie a asm file that looks "generic" but has a pic header and entry exit vars. If I wanted to say use a xyz accelerometer and the data sheet math was c as above, is using "math libs by someone" ok from anyone who has done that and not done their own maths subs from scratch. I mean use the code as in line asm in their program. If anyone has what was they're favourite and how easy was it to input output floating vars?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know if I do yet as I've not really studied the data sheet for the device just looked at python and c code and not had to implement more than simple math in GCB. As you say I'll probably only need scaling.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I know this thread is several months old but the comment by Joe Rocci would solve a problem.
I'm trying to get a BME280 sensor working. Floating Point variables are used in all the code samples I can find. I can get the sensor to work with an Arduino but I don't really know what I'm doing with C/Arduino. I can glue other ppls bits of code together and make it work, but that's not very satisfying.
I'm very BASIC :-)
So Joe how do you calculate a Single precision floating point variables using 32 bit (Long) variable +variable scaling ?
As far as I can see non of the data coming out of the sensor is a "float", they only appear when the rather complicated calculations begin.
I've looked at how "Floats" are stored i.e. +/-, Mantissa and number, so I can see that it's possible.
Is there any code that can do these type of calculations using only long variables?
I've never used variable scaling either
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@David. I have just scanned the web, a quick review of the datasheet and found some integer based methods on the Bosch web site - this is a quick review. However, this device does look like it can be supported in integer maths maybe using factorisation, This is SPI or I2C so all data at some point is in eight bits - :-) I could be making this too simple. Anyone what to send me one? - I can have a look.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium
What did you want sending?
I have Proton Basic code for I2C that I use as a sort of reference but it doesn't work with my HW.
I have Arduino code that does work but all the clever stuff is in the includes and I am not very good at C/C++
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Indeed. You have written include for the x,y,z accellerometer in my first post since sending you the device. The c++ code I had was..er, that and next best was picaxe code which was very similar to the include you wrote. Apparently there's a filter program, also in c++ that stabilises the data from device ie removes errors using big sums..everything looks big in c :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the Proton Basic Example.
I'm using a 16F887 but the Amacus 18 uses a PIC18F25K20. Same Pin out but it has 32K of flash.
I'm getting close to getting some output from the BME280, would that help too? I've configured it and can get data back, I just need to read up on what's next. From memory the pressure, humidity and temperature come in 3 x 32 bit blocks or maybe 2 x 32 + 1 x 16, something like that. That's the raw uncalibrated data, then comes the calibration, I haven't got that far yet.
I think a lot of the calculations come from the calibration data stored on the BME280. I assume it's different for each one. Pressure(altitude) calculations take up a lot of memory. http://www.protonbasic.co.uk/archive/index.php/t-75940.html
I can dig out the Arduino files if you want but the includes are C/C++
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK
I've just had another read , data comes out as 3 blocks of 2 x 20 bits + 1 x 16 bits, preferred method is burst read what ever that may be ;-) I'm assuming they mean read the whole 56 bits rather than trying to extract sections of it.
I've got some doubts about the configuration settings in the Proton Basic Example, so I'll change them too. Oversampling of x16 seems a bit extreme also Normal Mode ought to be Forced Mode.
Last edit: David Thompson 2017-09-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is of interest to me, also. I had bought some BMP280 s but haven't had a chance to work with them. Similar except the BME280 also has humidity.
"Burst read" in I2C for The BME280 would to send the starting register addr and Read control byte to the BME280 and then the BME would send registers 0xF7 thru 0xFE as one read, auto incrementing the register address in the BME280 for each successive read. Bosch suggests this versus the overhead of asking for each register individually.
The 20 bits you talk of are actually sent as three bytes ( 8bits each):
0xF7 MSB of Press
0xF8 LSB Press
0XF9 xLSB press 4- bits 7-4
0XFA MSB of Temperature
0xFB LSB Temp
0xFC xLSB Temp 4 bits
0xFD MSB of Humidity
0xFE LSB Humidity
So your code would ask to read 8 times a byte.
This part looks straight forward.
GL
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As with all ebay interesting devices the info is open to interpretation and the data sheets info is in there somewhere so I see how arduino users do it in c. Pic users don't...anything much.
That's the thing with using basic, re-inventing code... you unintentionally learn c as a bonus
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobum
After only a few days, I'm 10 years older!
I just cannot get GCB to work in I2C mode to this sensor I have 0.97 and 0.98 and I've tried 16f877a and 16f887. I reconnected to an Arduino everything works fine!
I've using 3 compilers, Oshonsoft, GCB and Proton (Free). I can't get proton to work in I2c either.
Oshonsoft works and I can output data and calibration data, but nothing changes, so it looks like the BME280 isn't starting a temp/hum/pressure read. Also the the temp/Hum/Pres data looks suspicious:
128,0,0,128,0,0,128,0
I've outputted all the data in 8 bit pieces.
If I hold the Sensor to warm it, nothing changes.
If I write a register then change it in the code, when I read it back it is as it was written. So all that's working, but it doesn't work!!!
I've tried various permutations of Normal/Forced Mode and Oversampling 2 & 8, makes no difference.
I feel that I'm missing something critica, it certainly isn't minor ;-)
Mmote I didn't use "burst mode" cause I don't know how :-( but that sounds like way to go.
I've never used a BMP180 but I've read that it uses the same protocol and maths. It has a minor difference but I can't remember what it was.
I have 3 of these devices, 2 x 5V and 1 x 3.3v The 3.3v also has SPI and I have another 3.3v SPI only device.
The 3 x I2C capable modules all work with Arduino. Only difference is ID 2 x 0x76, 1 x 0x77
Where are you located Anobium? Ah just checked Guilldford so not far away.
I'm willing to sponsor you with one if it helps. I have 2 x 5v versions which don't need a 5-3.3V level changer. So they would be good candidates. Alternatively I could treat you to one off Ebay and maybe a BMP180 as well.
Mr Mmotte if I understand you correctly, are you saying that if I read the 1st register of one of the 3 blocks of data (hum,temp & pres + 2 blocks of calibration) into a 32 bit variable, the BME will fill it up with the rest of the data?
Last edit: David Thompson 2017-10-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you been able to get I2C discovery working on the device? You have two options of Hardware I2C and Software I2C. I have justed tested on the bench here and using v0.98.00 both HW and SW I2C work to a 877a at 20mhz, therefore, I think we know this is ok here but is yours? I can see my I2C devices on my serial terminal. I just adapted the 16F866 discovery code for HW and SW I2C.
We need to been certain we can see your I2C device.
2, Yes, you can send - I have to look at the BMP180 library that was sent. You need to send me a SourceForge Private Message to share details.
I have not looked at these devices before - so, they better be good. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've tried a number of Discovery programs, some from v0.97 to 16f877a @ 12Mhz and similar from v0.98 to 16f887 @ 12Mhz. None were able to find the device ID.I got the display on the terminal but not address.
I also modified some to send straight to the BME280 address 0x77 (0xEF read) no respose at all. Same is true for Proton but I didn't try as many times. I checked if Oshonsoft was somehow cheating by changing the address but without the correct device address it does not work. I've got a I2C to LCD device, I'll try that later and see if I can discover it.
I'm just looking at this burst mode, although I was using for next, I don't see any other way than 1 byte at a time. I2C devad,regadr,databyte,adr,byte,adr,byte etc.
My main interest in them was its accuracy with Humidity. I tried to connect two SPI devices with one I bought before, but the BME280 died when I connected the 2nd device a Max7221. So now I'm trying I2C
They are also much more reliable than the DHT22 and its variants.
The BMP 180 is pressure only as against Pressure, Humidity and Temp for BME280. They were designed for use in mobile phones.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you check with a meter? What is the ohms when measured to the 5v line from the data line with no devices connected? and, the same for the clock line.
Re a PM. Click the Anobium blue URL text. Then, you should see PM at top (ish) right hand side of the web page.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 5V version is 10K but bear in mind there is a 5-3.3V device on the pcb. BME280 is 3.3V
The 3.3V version is 4.7K, these little boards have lots of SMD resistors so a lack of pullup would be a defect rather than an ommission.
Hells Teeth!! I just tried the LCD I2C device with Discovery and it works. I just tried both 5V BME280s and so do they. Goo, gah, giggle, burp, drool, I'm getting too old ;-)
Last edit: David Thompson 2017-10-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If these are the measure from the two lines to the suppy voltage then it would seem that you have pull-up resistors.
Please dig out the I2C LCD and see if you can discover the LCD. If you are not getting any discover of devices then we need to sort this first. Test the LCD please.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
LOL I've been timed out for over using personal messages! The line must be red hot, I've used it twice.
15 minutes wait
Anyway now they work I'm keeping them :-) Just kidding.
Last edit: David Thompson 2017-10-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just received a device, should be a BMP280, from DavidT in the post.
Hook up the four lines directly to a Microchip Xpress board. Then, loaded standard demo ..\GCB@Syn\GreatCowBasic\Demos\Vendor Boards\Xpress Evaluation Board\16 Show I2C Devices to Serial Terminal.gcbhere on GitHub and I got results I expected. A device on 0x71/0x71 is an EMC Sensor and the 0xEC/0xED is the BMP280. This test works. Screenshot is attached.
Question I expect to be asked... Why is the BMP280 on 0xEC? The device show is an 8-bit address when the bit 0 is the read or write bit, so, to get the 7-bit address you divide by 2. 0xEC/2d = 0x76. So, the I2C discovery had worked as expected.
Hi
It's a BME280, BMP180.
I'm pleased to see it's working. I'm just planning how to set up a 3.3v leveler for the SPI pcb I have.
After my earlier mishaps I'm going for belt and braces this time, I'm OK with SPI but I'll be having the same issues as I2C later so I'll keep an eye out on this thread.
Last edit: David Thompson 2017-10-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I want to use code from c that users 123.456/-654.321 in GCB there's pic code to do it. ie a asm file that looks "generic" but has a pic header and entry exit vars. If I wanted to say use a xyz accelerometer and the data sheet math was c as above, is using "math libs by someone" ok from anyone who has done that and not done their own maths subs from scratch. I mean use the code as in line asm in their program. If anyone has what was they're favourite and how easy was it to input output floating vars?
Why do you need floating point math? What kind calculations do you have to make that can't be done with long integer math and variable scalimg?
I don't know if I do yet as I've not really studied the data sheet for the device just looked at python and c code and not had to implement more than simple math in GCB. As you say I'll probably only need scaling.
Hi
I know this thread is several months old but the comment by Joe Rocci would solve a problem.
I'm trying to get a BME280 sensor working. Floating Point variables are used in all the code samples I can find. I can get the sensor to work with an Arduino but I don't really know what I'm doing with C/Arduino. I can glue other ppls bits of code together and make it work, but that's not very satisfying.
I'm very BASIC :-)
So Joe how do you calculate a Single precision floating point variables using 32 bit (Long) variable +variable scaling ?
As far as I can see non of the data coming out of the sensor is a "float", they only appear when the rather complicated calculations begin.
I've looked at how "Floats" are stored i.e. +/-, Mantissa and number, so I can see that it's possible.
Is there any code that can do these type of calculations using only long variables?
I've never used variable scaling either
@David. I have just scanned the web, a quick review of the datasheet and found some integer based methods on the Bosch web site - this is a quick review. However, this device does look like it can be supported in integer maths maybe using factorisation, This is SPI or I2C so all data at some point is in eight bits - :-) I could be making this too simple. Anyone what to send me one? - I can have a look.
Hi Anobium
What did you want sending?
I have Proton Basic code for I2C that I use as a sort of reference but it doesn't work with my HW.
I have Arduino code that does work but all the clever stuff is in the includes and I am not very good at C/C++
If someone sends me a sample I call look at the device. :-)
If you have a URL to Proton BASIC code - that is a great starting point.
Indeed. You have written include for the x,y,z accellerometer in my first post since sending you the device. The c++ code I had was..er, that and next best was picaxe code which was very similar to the include you wrote. Apparently there's a filter program, also in c++ that stabilises the data from device ie removes errors using big sums..everything looks big in c :)
Here is the Proton Basic Example.
I'm using a 16F887 but the Amacus 18 uses a PIC18F25K20. Same Pin out but it has 32K of flash.
I'm getting close to getting some output from the BME280, would that help too? I've configured it and can get data back, I just need to read up on what's next. From memory the pressure, humidity and temperature come in 3 x 32 bit blocks or maybe 2 x 32 + 1 x 16, something like that. That's the raw uncalibrated data, then comes the calibration, I haven't got that far yet.
I think a lot of the calculations come from the calibration data stored on the BME280. I assume it's different for each one. Pressure(altitude) calculations take up a lot of memory.
http://www.protonbasic.co.uk/archive/index.php/t-75940.html
I can dig out the Arduino files if you want but the includes are C/C++
Upload as a ZIP your program as far as you have it working. This looks relatively simple.
I will have look.
OK
I've just had another read , data comes out as 3 blocks of 2 x 20 bits + 1 x 16 bits, preferred method is burst read what ever that may be ;-) I'm assuming they mean read the whole 56 bits rather than trying to extract sections of it.
I've got some doubts about the configuration settings in the Proton Basic Example, so I'll change them too. Oversampling of x16 seems a bit extreme also Normal Mode ought to be Forced Mode.
Last edit: David Thompson 2017-09-30
This is of interest to me, also. I had bought some BMP280 s but haven't had a chance to work with them. Similar except the BME280 also has humidity.
"Burst read" in I2C for The BME280 would to send the starting register addr and Read control byte to the BME280 and then the BME would send registers 0xF7 thru 0xFE as one read, auto incrementing the register address in the BME280 for each successive read. Bosch suggests this versus the overhead of asking for each register individually.
The 20 bits you talk of are actually sent as three bytes ( 8bits each):
0xF7 MSB of Press
0xF8 LSB Press
0XF9 xLSB press 4- bits 7-4
0XFA MSB of Temperature
0xFB LSB Temp
0xFC xLSB Temp 4 bits
0xFD MSB of Humidity
0xFE LSB Humidity
So your code would ask to read 8 times a byte.
This part looks straight forward.
GL
Mike
Things just seem to happen at the same time, or, do they?
I have in my inbox a library and demo for the BMP180. It arrived yesterday. This is an operational library for the BMP180 - yes, it needs testng etc.
Is the BMP180 the same as the BMP280 in terms of protocol and maths? If yes - then we have alignment... if not, :-(
Let me know.
Anobium
As with all ebay interesting devices the info is open to interpretation and the data sheets info is in there somewhere so I see how arduino users do it in c. Pic users don't...anything much.
That's the thing with using basic, re-inventing code... you unintentionally learn c as a bonus
Hi Anobum
After only a few days, I'm 10 years older!
I just cannot get GCB to work in I2C mode to this sensor I have 0.97 and 0.98 and I've tried 16f877a and 16f887. I reconnected to an Arduino everything works fine!
I've using 3 compilers, Oshonsoft, GCB and Proton (Free). I can't get proton to work in I2c either.
Oshonsoft works and I can output data and calibration data, but nothing changes, so it looks like the BME280 isn't starting a temp/hum/pressure read. Also the the temp/Hum/Pres data looks suspicious:
128,0,0,128,0,0,128,0
I've outputted all the data in 8 bit pieces.
If I hold the Sensor to warm it, nothing changes.
If I write a register then change it in the code, when I read it back it is as it was written. So all that's working, but it doesn't work!!!
I've tried various permutations of Normal/Forced Mode and Oversampling 2 & 8, makes no difference.
I feel that I'm missing something critica, it certainly isn't minor ;-)
Mmote I didn't use "burst mode" cause I don't know how :-( but that sounds like way to go.
I've never used a BMP180 but I've read that it uses the same protocol and maths. It has a minor difference but I can't remember what it was.
I have 3 of these devices, 2 x 5V and 1 x 3.3v The 3.3v also has SPI and I have another 3.3v SPI only device.
The 3 x I2C capable modules all work with Arduino. Only difference is ID 2 x 0x76, 1 x 0x77
Where are you located Anobium? Ah just checked Guilldford so not far away.
I'm willing to sponsor you with one if it helps. I have 2 x 5v versions which don't need a 5-3.3V level changer. So they would be good candidates. Alternatively I could treat you to one off Ebay and maybe a BMP180 as well.
Mr Mmotte if I understand you correctly, are you saying that if I read the 1st register of one of the 3 blocks of data (hum,temp & pres + 2 blocks of calibration) into a 32 bit variable, the BME will fill it up with the rest of the data?
Last edit: David Thompson 2017-10-01
@David - do not get older at that rate.
A couple of questions.
We need to been certain we can see your I2C device.
2, Yes, you can send - I have to look at the BMP180 library that was sent. You need to send me a SourceForge Private Message to share details.
I have not looked at these devices before - so, they better be good. :-)
I've tried a number of Discovery programs, some from v0.97 to 16f877a @ 12Mhz and similar from v0.98 to 16f887 @ 12Mhz. None were able to find the device ID.I got the display on the terminal but not address.
I also modified some to send straight to the BME280 address 0x77 (0xEF read) no respose at all. Same is true for Proton but I didn't try as many times. I checked if Oshonsoft was somehow cheating by changing the address but without the correct device address it does not work. I've got a I2C to LCD device, I'll try that later and see if I can discover it.
I'm just looking at this burst mode, although I was using for next, I don't see any other way than 1 byte at a time. I2C devad,regadr,databyte,adr,byte,adr,byte etc.
My main interest in them was its accuracy with Humidity. I tried to connect two SPI devices with one I bought before, but the BME280 died when I connected the 2nd device a Max7221. So now I'm trying I2C
They are also much more reliable than the DHT22 and its variants.
The BMP 180 is pressure only as against Pressure, Humidity and Temp for BME280. They were designed for use in mobile phones.
I think we need to get confidence in I2C discovery. Do you have pull-up resistors fitted to the data and clock lines?
I did on the 3.3v device because it used a 3.3 to 5v level changer. The 5V version has all the 3.3v conversion on the pcb, so I'd guess yes.
How do you send a Private message? If I can get your details, I'll post a 5v one to you. That will take any errors by me out of the loop
Last edit: David Thompson 2017-10-01
Can you check with a meter? What is the ohms when measured to the 5v line from the data line with no devices connected? and, the same for the clock line.
Re a PM. Click the Anobium blue URL text. Then, you should see PM at top (ish) right hand side of the web page.
The 5V version is 10K but bear in mind there is a 5-3.3V device on the pcb. BME280 is 3.3V
The 3.3V version is 4.7K, these little boards have lots of SMD resistors so a lack of pullup would be a defect rather than an ommission.
Hells Teeth!! I just tried the LCD I2C device with Discovery and it works. I just tried both 5V BME280s and so do they. Goo, gah, giggle, burp, drool, I'm getting too old ;-)
Last edit: David Thompson 2017-10-01
If these are the measure from the two lines to the suppy voltage then it would seem that you have pull-up resistors.
Please dig out the I2C LCD and see if you can discover the LCD. If you are not getting any discover of devices then we need to sort this first. Test the LCD please.
LOL I've been timed out for over using personal messages! The line must be red hot, I've used it twice.
15 minutes wait
Anyway now they work I'm keeping them :-) Just kidding.
Last edit: David Thompson 2017-10-01
Progess Report.
Just received a device, should be a BMP280, from DavidT in the post.
Hook up the four lines directly to a Microchip Xpress board. Then, loaded standard demo
..\GCB@Syn\GreatCowBasic\Demos\Vendor Boards\Xpress Evaluation Board\16 Show I2C Devices to Serial Terminal.gcb
here on GitHub and I got results I expected. A device on 0x71/0x71 is an EMC Sensor and the 0xEC/0xED is the BMP280. This test works. Screenshot is attached.Question I expect to be asked... Why is the BMP280 on 0xEC? The device show is an 8-bit address when the bit 0 is the read or write bit, so, to get the 7-bit address you divide by 2. 0xEC/2d = 0x76. So, the I2C discovery had worked as expected.
Now, to do same on UNO/Mega328p
Hi
It's a BME280, BMP180.
I'm pleased to see it's working. I'm just planning how to set up a 3.3v leveler for the SPI pcb I have.
After my earlier mishaps I'm going for belt and braces this time, I'm OK with SPI but I'll be having the same issues as I2C later so I'll keep an eye out on this thread.
Last edit: David Thompson 2017-10-03