Previous posts for this project:
- [AirCare] InTheAir - Project Description
- [AirCare] InTheAir - Week 1: Getting a Launchpad to Blink
- [AirCare] InTheAir - Week 2: Preparing the Beaglebone Black
- [AirCare] InTheAir - Week 3: Fuel Tank Testing
- [AirCare] InTheAir - Week 4: Using the CC3200
- [AirCare] InTheAir - Week 5: openHAB and MQTT
Introduction
Last week, I set up openHAB to visualise data on my FuelTank's battery state. But how did I access this data from the CC3200? Let's find out ...
Energia & CC3200 on Mac
But first ... another problem was solved!
At long last, the CC3200 is working with Energia on my Mac, thanks to pmohan for pointing me to the solution. The issue was caused by the latest version of OSX (Yosemite) not allowing to run unsigned drivers ("kext").
Using a manual fix which disables the signature checking in OSX, the driver can be loaded and the CC3200 detected in Energia! Woop!
Trial & error
During my research, I came across some posts and reviews by peteroakes in which he created an Energia sketch to retrieve some statistics from the Fuel Tank BoosterPack via I2C.
I hooked up the Fuel Tank Boosterpack to the CC3200, loaded the sketch in Energia and monitored the serial output. Nothing spectacular happened.
All values were "0". This meant that either the sketch would somehow not be compatible with the CC3200 or that the I2C slave was unreachable.
Searching a bit more, I came across a library (it's at the bottom of that page - or here) doing the same thing, and the result was unfortunately the same. (What was I expecting ??)
Recovering the battery
At some point, I connected the Fuel Tank to the CC3200 and had it run on the battery without charger.
Unfortunately, the battery discharged a bit faster than expected, while I was away at work.
The result ? By the time I got home, the battery would no longer charge via the Fuel Tank when connected to a power source.
Looking through the Fuel Tank's documentation, there is a trick to "kickstart" the charging of the battery in case it was discharged too much.
The procedure is described in paragraph 6 of the user guide and helped me recover the battery, after which it was charging with the Fuel Tank again.
Pinout diagrams
In order to troubleshoot the problem, I searched pinouts of both the CC3200 and the Fuel Tank BoosterPack. I found both on the Energia website.
What I noticed based on these diagrams, is that the Fuel Tank BoosterPack seems to have multiple I2C pins!
Using jumper wires, I tested the different I2C pins of the BoosterPack with the CC3200, until I found a working set.
After that, I connected the BoosterPack to the CC3200 and used the jumper wires on the CC3200 directly. Like so:
(Fritzing part for the CC3200 was found here: New CC3200 Launchpad Fritzing Part)
I removed the jumpers connecting the onboard sensors to the I2C bus and connected jumpers to the I2C pins attached to the underlying BoosterPack.
Because I removed the jumpers of the onboard sensor, I had to ensure the "pull-up" jumper on the BoosterPack was in place. You can verify the pull-ups are ok if the green and orange LEDs of the CC3200 are on.
With this little manipulation, I was finally having proper readings on the Fuel Tank's data with both Peter's code and the library:
Glitches in the readings
I did notice some glitches in the values read when doing the following:
- connecting/disconnecting a charging source
- having the CC3200 connected via USB to PC (for Serial output) at the same time
Sketch
This is my current sketch. It's still very basic and rough, but it does the trick for now.
It will need to be improved to go into deep sleep after sending the values, until the next set of values is to be sent.
#include <WiFi.h> #include <PubSubClient.h> // Core library for code-sense #if defined(WIRING) // Wiring specific #include "Wiring.h" #elif defined(MAPLE_IDE) // Maple specific #include "WProgram.h" #elif defined(MPIDE) // chipKIT specific #include "WProgram.h" #elif defined(DIGISPARK) // Digispark specific #include "Arduino.h" #elif defined(ENERGIA) // LaunchPad MSP430, Stellaris and Tiva, Experimeter Board FR5739 specific #include "Energia.h" #elif defined(CORE_TEENSY) // Teensy specific #include "WProgram.h" #elif defined(ARDUINO) && (ARDUINO >= 100) // Arduino 1.0 and 1.5 specific #include "Arduino.h" #elif defined(ARDUINO) && (ARDUINO < 100) // Arduino 23 specific #include "WProgram.h" #else // error #error Platform not defined #endif // Include application, user and local libraries #include "Wire.h" #include "FuelTankLibrary.h" WiFiClient wclient; byte ip[] = { 172, 16, 0, 100 }; PubSubClient client("iot.eclipse.org", 1883, callback, wclient); FuelTank myFuelTank; #define WIFI_SSID "wifi57" #define WIFI_PWD "**********" void callback(char* inTopic, byte* payload, unsigned int length) { // Handle callback here } void setup() { Wire.begin(); myFuelTank.begin(); } void loop() { publishData(); delay(300000); } void publishData() { WiFi.begin(WIFI_SSID, WIFI_PWD); while(WiFi.localIP() == INADDR_NONE) { delay(300); } // Give some time to settle delay(5000); char content[10]; if (client.connect("CC3200-Room-1")) { myFuelTank.get(); sprintf(content, "%d", myFuelTank.voltage_mV()); client.publish("cc3200-fvan\/voltage", content); sprintf(content, "%d", myFuelTank.timeToEmpty_mn()); client.publish("cc3200-fvan\/tte", content); sprintf(content, "%d", myFuelTank.stateOfCharge_Percent()); client.publish("cc3200-fvan\/soc", content); client.disconnect(); } delay(500); WiFi.disconnect(); }
The result of the data being received, as seen from openHAB:
Top Comments