Forum Replies Created
-
AuthorPosts
-
I’m sorry; I’ve spent a lot of time reading through that firmware and if there’s something you have to do to get it to start taking readings, I don’t know what it is. So either I’m just not understanding the firmware or that’s not the firmware that’s actually on your device. I don’t think there’s any other way I can help you if you cannot get a summary of the commands and registers from Northern Widget. The problem is definitely NOT your Mayfly.
All of the Atlas sensors do have a built in sleep command that you can use for low power without needing the isolator. You should be able to add ‘RTD.send_cmd(“SLEEP”);’ and ‘EC.send_cmd(“SLEEP”);’ to your system sleep function.
I’m sorry I’m late to the game on this one.
Shannon said more clearly what I would have said. But re-reading, I remember that the Atlas sensors are special. You can’t cut the power to the Atlas circuits while they’re connected to the I2C bus of the Mayfly or your program will crash. The Atlas circuits have the I2C lines pulled up to the voltage in line. If you set the voltage in to ground (ie, turn it off) the I2C lines get pulled down as well. The Arduino I2C (Wire) library hangs forever when that happens. So if you want to power down your Atlas sensors you need to get an isolator.
So it is there and responding, but there’s something wrong with my code because it’s not giving data. Do you know if the firmware on your device *is* that code on github? Otherwise, I don’t see in that code what I have to do to get it to start reporting values.
Also try flipping the SCL and SDA pins if you’re getting nothing. Some versions of the Mayfly had them labeled backwards.
Also on a Mayfly you should always be finding a device at 0x48 and at 0x68. Those are the clock and the extra ADC. If the Walrus is responding, it should show up as a third device.
Scanner code for the Mayfly:
Arduino12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// This sketch tests the standard 7-bit addresses// Devices with higher bit address might not be seen properly.//#include <Arduino.h>#include <Wire.h>void scan() {byte error, address;int nDevices;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");}void setup() {pinMode(22, OUTPUT);Serial.begin(9600);Serial.println("\nI2C Scanner");digitalWrite(22, HIGH);Wire.begin();}void loop() {Serial.println("Hardware I2C Objects:");scan();delay(5000); // wait 5 seconds for next scan}If (when) that fails, you can try an I2C scanner program on the Mayfly to see if the sensor has a different address.
Ok, here’s new code for the Mayfly. This should be much more verbose and show more clearly if the sensor’s responding.
C++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159#include <Arduino.h>#include <Wire.h>#define DEVICE_I2C_ADDRESS \0x4D // I *think* this is the address it's using for itself// https://github.com/NorthernWidget-Skunkworks/Project-Walrus/blob/b5d9cc1fdfe2cf16fb5048a1f9ff0b27253c3a94/Firmware/Walrus_I2C_5BA/Walrus_I2C_5BA.ino#L155// A helpful union for flipping between bytes to longstypedef union leFrame {byte Byte[4]; // 4 bytes will occupy 4 bytesuint32_t uInt32; // a single float occupies 4 bytes} leFrame;void setup() {Wire.begin(); // join i2c bus (address optional for master)Serial.begin(9600); // start serial for output// NOTE: Something may have to happen here to "start the thing up"// I can't tell if they intend that or not}void loop() {// The control register (0x00) has the bottom two bits as the update rate// and the top bit as the ready flag// update rate options appear to be:// 0x00 - 5s// 0x01 - 10s// 0x02 - 60s// 0x03 - 300s (5 min)// As far as I can tell, if not set it *should* be on 5suint8_t attempts = 1;byte control_flag = 0;while (control_flag == 0 && attempts <= 10) {Wire.beginTransmission(DEVICE_I2C_ADDRESS); // select device with "beginTransmission()"Wire.write(0x00); // select starting register with "write()"Wire.write(0x01); // write the bottom bit to the fastest update rateWire.endTransmission(); // end write operation, as we just wanted to// select the starting registerWire.requestFrom(DEVICE_I2C_ADDRESS,1); // select number of bytes to get from the device// give it half-a-second to respond (this is WAY overkill for the I2C// specs)uint32_t start = millis();while (!Wire.available() && millis() - start < 500) {}if (Wire.available()) {byte control_reg = Wire.read();control_flag = bitRead(control_flag, 7);Serial.print("Got response from Walrus. Current state: ");Serial.println(control_flag);} else {Serial.print("Attempt ");Serial.print(attempts);Serial.println(" got no response from Walrus.");attempts++;}}if (attempts == 10) {Serial.println("Got now response from Walrus after 10 attempts.");Serial.println("Is the sensor powered at 3.3V?");Serial.println("Are the I2C pins connected correctly? Try reversing ""them if you're not sure.");Serial.println("Retrying in 30 seconds.");delay(30000L);return;}// We'll try reading all the registers at once sequentially instead of// reading one after the other// the registers are loaded starting on line 242:// https://github.com/NorthernWidget-Skunkworks/Project-Walrus/blob/master/Firmware/Walrus_I2C_5BA/Walrus_I2C_5BA.ino#L242Wire.beginTransmission(DEVICE_I2C_ADDRESS); // select device with "beginTransmission()"Wire.write(0x02); // select starting register with "write()"// the first data register is pressure starting in register 0x02Wire.endTransmission(); // end write operation, as we just wanted to select// the starting register// select number of bytes to get from the device// + 4 for pressure in microbars (ie mbar*1000)// + 4 for temp0 - This is the temperature from the MCP9808 (*10000.0)// + 4 for temp1 - This is the temperature from the MS5803 (*10000.0)Wire.requestFrom(DEVICE_I2C_ADDRESS, 12);// We won't bother to read the next 8 bytes of unchanging sensor// information:// + 2 for model (uint16_t)// + 2 for group id (uint16_t)// + 2 for "INDID" ?dummy? (uint16_t)// + 2 for firmware id (uint16_t))// my helpful unionleFrame fram;// NOTE: may need to flop endinaness for the values.// if getting garbage, try switching all for loops to// 'for (int8_t i = 0; i<4; i++)'// get pressure from the first 4 bytes, reversing order/endiannessSerial.println("\nreading pressure...");fram.uInt32 = 0;for (int8_t i = 4; i; i--) {fram.Byte[i] = Wire.read();Serial.print("Byte ");Serial.print(i);Serial.print(": ");Serial.println(fram.Byte[i]);}Serial.print("uint32_t: ");Serial.println(fram.uInt32);float pressure = fram.uInt32 / 1000;Serial.println();// get MCP9808 temp from the next 4 bytes, reversing order/endiannessSerial.println("reading pressure...");fram.uInt32 = 0;for (int8_t i = 4; i; i--) {fram.Byte[i] = Wire.read();Serial.print("Byte ");Serial.print(i);Serial.print(": ");Serial.println(fram.Byte[i]);}Serial.print("uint32_t: ");Serial.println(fram.uInt32);float temp_mcp9808 = fram.uInt32 / 10000;Serial.println();// get MS5803 temp from the last 4 bytes, reversing order/endiannessSerial.println("reading pressure...");fram.uInt32 = 0;for (int8_t i = 4; i; i--) {fram.Byte[i] = Wire.read();Serial.print("Byte ");Serial.print(i);Serial.print(": ");Serial.println(fram.Byte[i]);}Serial.print("uint32_t: ");Serial.println(fram.uInt32);float temp_ms5803 = fram.uInt32 / 10000;Serial.println();// Serial.print the resultsSerial.print("MS5803 Pressure: ");Serial.print(pressure);Serial.println(" mbar");Serial.print("MCP9808 Temperature: ");Serial.print(temp_mcp9808);Serial.println(" °C");Serial.print("MS5803 Temperature: ");Serial.print(temp_ms5803);Serial.println(" °C");// wait 5s and then repeatSerial.println("---");delay(5000);}No, it’s just *printing* something. I don’t think the sensor’s responding.
That’s the full code, you should upload it to the mayfly with the sensor powered and attached to the I2C on the Mayfly. Then start a serial terminal at 9600 and you should see output.
No, no, that’s for a Mayfly talking to a sensor with the firmware Northern Widget posted on GitHub.
-
AuthorPosts