Hi everyone,
I used to have ton of arduino pro mini with some bme280 sensors, and i decided to try moteino r6 (8mhz)
I then flashed it with optiboot from https://github.com/hallard/Pro-Mini-ICSP-FTDI/blob/master/bootloaders/optiboot_flash_atmega328p_57600_8MHZ.hex.
I tried rfm95w module, everything works great, i reach ~65 km (-126dBm) from my house to a mountain top but i have an issue for i2c
So my first question is why there is no pull up 4.7K resistor on SCL, SDA ?
Second, is despite attempting 0x76 address, 0x77 or event the classic sketch about scanning all i2c ports, everytime i try
some i2c interaction, the board simply hang, like it would have crashed
I have this simple sketch:
#include <SparkFunBME280.h>
#include <Arduino.h>
#include <Wire.h>
#define SERIAL_BAUD 9600
BME280 bme280;
float temperature=0;
char Fstr[10];
float humidity=0;
char Hstr[10];
float pressure=0;
char Pstr[10];
void setup() {
Serial.begin(9600);
Serial.println("Start");
bme280.settings.commInterface = I2C_MODE;
bme280.settings.I2CAddress = 0x77;
bme280.settings.I2CAddress = 0x76;
bme280.settings.runMode = 3;
bme280.settings.tStandby = 0;
bme280.settings.filter = 0;
bme280.settings.tempOverSample = 1;
bme280.settings.pressOverSample = 1;
bme280.settings.humidOverSample = 1;
Serial.println("Setup Done");
}
void loop() {
bme280.begin();
Serial.println("THIS will never be printed");
dtostrf(bme280.readTempF(), 3,1, Fstr);
Serial.println(Fstr);
}
And it print
Start
Setup Done
And that's it, nothing happen after that, if i put the bme.begin in the setup funtion, it's the same issue of course, it will never reach the "Setup Done"
If i try a classic if...else
if (! bme.begin(0x76)) {
Serial.println("no bme found");
}
else{
Serial.println("bme OK");
}
nothing will be printed, i would expect at least no bme found :(
Im i missing something essential compared to a classic arduino mini pro ?
Thanks a lot everyone :)
I believe you need to use the begin method for the type of interface you're using. Therefore,
bme280.beginI2C();
Also, the begin call should be in setup(), not within loop().
Hi Tom, thanks for your suggestion, but it didn't made the trick.
Even if i don't connect the bme280, it still hang at the method begin() , no matter what, while on pro mini, it simply print no bme connected.
If i try the I2C scanner
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
It print
I2C Scanner
Scanning...
While in worst case scenario, it should have also print No I2C devices found
And hang, i can wait 1h, nothing :(
Could it be due to the optiboot firmware i installed ?
Your BME280 ... is on a breakout?
And are you using code that is known to work on other atmega328/8mhz?
Why not use a library?
I have posted some sketches in this repository (https://github.com/LowPowerLab/rfM69/tree/master/Examples) which are known to work with the LowPowerLab BME280 based boards.
Of course i2c needs pullups - 4.7K are middle of the road good values.
Do you have a logic analyzer?
Hi Felix, i have currently 7 pro mini running 8 mhz (no reg, no led)with bme280 for monitoring my plants and send data with Lora.
So my sketches usually works ;)
here is my default sketch for all of them (this one use tpl5110 and interrupts, so there is a bit of more fun ofc)
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <Arduino.h>
#include <rBase64.h>
#include <ArduinoJson.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "PinChangeInterrupt.h"
#define SEALEVELPRESSURE_HPA (1013.25)
#define NSS 10
#define RST A0
#define DI0 2
#define SCK 13
#define MISO 12
#define MOSI 11
#define BAND 868E6
#define BLUE_LED 13
#define SF_FACTOR 7
const int drvPin = A2;
const int DONEPin = A1;
bool sendData = true;
Adafruit_BME280 bme;
void do_smth(void) {
sendData = true;
}
long readVcc() {
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
uint8_t low = ADCL;
uint8_t high = ADCH;
long result = (high<<8) | low;
result = 1125300L / result;
return result;
}
void setup() {
Serial.begin(9600);
if (! bme.begin(0x76)) {
Serial.println("no bme found");
while (1);
}
bme.setSampling(
Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::FILTER_OFF);
delay(10);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND)) {
Serial.println("no lora");
while (1);
}
LoRa.setSpreadingFactor(SF_FACTOR);
LoRa.setTxPower(10);
pinMode(drvPin, INPUT_PULLUP);
pinMode(DONEPin, OUTPUT);
attachPCINT(digitalPinToPCINT(drvPin), do_smth, FALLING);
SMCR |= (1 << 2);
SMCR |= 1;
}
void goToSleep()
{
LoRa.sleep();
ADCSRA &= ~(1 << 7);
MCUCR |= (3 << 5);
MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6);
__asm__ __volatile__("sleep");
}
void loop() {
if (sendData)
{
ADCSRA |= (1 << 7);
String payload;
bme.takeForcedMeasurement();
int batt = (int)(readVcc());
payload = String("d=i,t="+String(bme.readTemperature())+",h="+String(bme.readHumidity())+",b="+String(batt));
LoRa.beginPacket();
LoRa.print(payload);
LoRa.endPacket();
sendData = false;
digitalWrite(DONEPin, HIGH);
delay(1);
digitalWrite(DONEPin, LOW);
goToSleep();
}
}
The sketch about I2C scanner is a classic one in order to debug from which address I2C are connected, so
it's not a bme280 issue here, its simply that any call to I2C end up with a hang, and i'm not quite
sure what is so different with a pro mini :(
ps: sorry for indentation, no idea why its not aligned while on atom, it perfectly is
How are you powering the board?
It must be powered from 3.3V (not more!) or you will damage the BME280. There is no LDO on Moteino-8mhz.
I test all my BME280 boards with a Moteino so it should work as long as wiring and sensor are functional.
I guess I don't get it either. Should be the same thing. Same MCU, same speed.
Did you use the Moteino as target in the IDE?
Powering the board like i do with my pro mini that i removed their voltage regulator.
A lipof4 battery 3.3V. No really im running out of idea :( It must be the firmware optiboot i flashed. Coz on my pro-mini, i run the default
firmware, so that's basically the only difference i see so far.
Can anyone spare the firmware you use for your moteino ? I want the smallest possible but even more important, the fastest to boot,
that's why i went for optiboot. Because i want to power down the whole board with a TPL5110, not using interrupts this time,
just powering it off and turn it on once every hour, so i can check how long i can last on a CR2032 coin cell. Hopefully a year^^
And yes, on platform.io, i use moteino as target ;)
Thanks a lot ;)
All Moteinos come with Dualoptiboot, so you can reflash the standard optiboot if you dont plan to try wireless reflashing.
Perhaps you may want to match the fuses to the pro mini.
Otherwise, it's just an atmega328p.
Finally found the issue, not the root cause though.
I reflashed the moteino with atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
instead of this optiboot firmware from charles hallard, and now it works like a charm
again ;)
Thanks you all for having tried to help me anyway, it was very nice ! :)
EDIT: yet i solder the rfm95W back, it hang again :'( look like its either the i2c, either the rfm95W, but not both at the
same time
EDIT2: soldered a second moteino R6, all works :)
Quote from: josua-alibast on August 04, 2019, 05:59:01 AM
EDIT2: soldered a second moteino R6, all works :)
Can you elaborate? I think I'm having a similar problem with a Moteino 8MHz--when I run the i2c_scanner with an I2C device connected (a SHT-30-D temperature sensor) it hangs in the same place. Was it the Moteino that ended up being faulty? Did you have to use flash the regular firmware on the second Moteino?
Thank you so much!