John Shovic's Google Plus Switch: 2013

Thursday, December 26, 2013

Where to find ProjectCuracao software

We have been asked where to find the most current software that has been released for ProjectCuracao.

This software is hosted at github.

http://github.com/projectcuracao

There will be a new release this weekend.

Wednesday, December 18, 2013

GPIO and I2C mappings for Project Curacao

We have been asked to put together tables showing the i2c and GPIO mappings for both the Raspberry Pi and the Arduino Battery Watchdog in Project Curacao.  While you can figure it out from the software and comments, it would be great to have the mappings in one place.  We are also putting this in Article 5, Project Curacao Software.  Updated with solar/wind GPIOs on 01/07/14.


RaspBerry Pi i2c Mappings

i2c addressDeviceFunction
0x29BM017 / TCS34725RGBC Color Sensor
0x39TSL2561Luminosity Sensor
0x40INA219Raspberry Pi Input Voltage/Current
0x41INA219Battery Input Voltage/Current
0x44INA219Solar Panel Output Voltage/Current
0x48ADS1915 A/D12 bit A/D converter
Channel 0Pi Battery Temperature
Channel 1Camera Servo Feedback Potentiometer
0x77BMP085Baro/Temp readings

RaspBerry Pi GPIO Mappings (GPIO.setmode(GPIO.board))

RPI.GPIORaspberry Pi NameBCM2835Pin NumberFunction
7GPIO7GPIO4P1_07Rising Edge Interrupt to Arduino
8TXDGPIO14P1_08TXD to Arduino
10RXDGPIO15P1_10RXD to Arduino
12GPIO1GPIO18P1_12Software PWM for Camera Servo
15GPIO3GPIO22P1_15Pulse to Turn Fan Off
16GPIO4GPIO23P1_16DHT22 Temp/Hum Interface
18GPIO5GPIO24P1_18Pulse to Turn Fan On
22GPIO6GPIO25P1_22Activity LED



Arduino Battery Watchdog i2c Mappings



i2c addressDeviceFunction
0x40INA219Arduino Input Voltage/Current
0x41INA219Arduino Solar Cell Voltage/Current
0x44INA219Arduino Battery Voltage/Current
0x5CAMS 2315Outside Temp/Humidity
0x68RTC1307Real Time Clock

Arduino Battery Watchdog GPIO Mappings

GPIOFunctionComments
22Interrupt PiLevel
27Pi Latched Relay ResetPulse
29Pi Latched Relay SetPulse
35LED Pi Interrupt OnArduino Battery Voltage/Current
41Select Wind SetWind Turbine
43Select Solar ResetSolar Panels


Arduino Battery Watchdog A/D Mappings


ChannelFunction
A3Pi Battery Voltage
A5Regulated Wind Voltage
A7Unregulated Wind Voltage
A9Pi Solar Voltage

Tuesday, December 17, 2013

Project Curacao Deployment Date Set

March 7th, 2014 has been set as the Project Curacao deployment date in Curacao.  The box will fly down with us in checked luggage with the batteries removed.  We will provide the TSA with a description of the box (it is bound to be inspected) and articles that we have written about the project.  A friend of ours has flown technical gear many times and always provides a list of materials and what are the devices in the luggage.  He has even gotten thank you notes from the TSA.

Here is a picture of the tower to which Project Curacao will be attached.  The camera will certainly have a good view.


We have to work out an attachment mechanism as the flat of the tower does not face directly south and we want to be facing south to maximize the solar power.

Software Status on Project Curacao (12/17/13)

As of today, the current state of the software in Project Curacao is as follows:

- Arduino Battery Watchdog:  The watchdog is reading and reporting data back to the main software in the Pi via a serial link through level shifters.  



  1. The read from Pi to Arduino fails occasionally (and is logged on the Pi) but not often enough to worry about at this point.  The next three things to be implemented
  2. Pi power control - Complete and now in system testing.  Implemented own alarm system (instead of using Time/TimeAlarms) using RTC because putting the Arduino to deep sleep also puts the internal software clock to sleep. 
  3. Watchdog logging - Partially implemented in SRAM.  Next is to put in logging in the Arduino for major events and implement sending the log to the Pi.  Then we will put together the software in RasPiConnect for showing the last 20 Arduino log entries.
  4. Watchdog function complete in Project Curacao main program and Arduino.  Tested pretty throughly.  Purposely crashed the main program every hour and and the Arduino rebooted the Pi after 15 minutes as expected.

- Project Curacao Pi main program:  The main program is generating all the graphs, camera pictures, environment sensing as required.  It is also regulating the Fan automatically now.    Not yet reading log files from the Arduino Watchdog.  Next three things to be implemented:

  1. Watchdog implementation complete
  2. Logging Arduino Watchdog Data - in progress
  3. Improving sensor error detection




- RasPiConnect:  We have a few more graphs and dials and buttons to implement on the RasPiConnect software, but it's pretty close to final.  We use this all the time now to monitor what is going on in the project remotely.   We are thinking it might be good to put in a process monitor graph and reboot function.  Both are easily done. 


  1. Added support for the new RasPiConnect alarms, but they really don't do anything yet.  
  2. Will add Arduino Battery Watchdog log print shortly. 
Here's the newest main screen (1 of 6 at this point):



Tuesday, December 10, 2013

Bootloader Issues with Arduino Mega 2560

Hit a significant roadblock on the Battery Watchdog last week.  During one development session, the Arduino Mega 2560 we are using for the Watchdog stopped taking programming, giving a series of errors:


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

After eliminating the possibility of a bad Arduino Mega, bad programming environment, bad cable, and others, we determined that we had run into the "!!!" bug.  The "!!!" bug can happen because you have "!!!" in an text string or, unfortunately, generated by the compiler as part of the code.  Eliminating the text string, we suspected that the code contained 0x212121.  We verified this by looking at the battery watchdog hex file and found a sequence of "212121" which in ascii, is "!!!".  It is generated by the code and not part of a text string in the program.

We used "hexdump" on the mac command line and then searched for the value.  We found the location of the compiled file by turning on the additional compilation output (on the Arduino preferences menu) and then looking through the compile information to find the .hex file.


The Bootloader that is shipped with some Megas (we bought ours early in 2013) detects the "!!!" sequence and goes into a monitor mode, hence timing out the loading process.

This is fixed in the latest boot loader (which also reenables the internal watchdog timer, Yes!).

We have now completed the process of flashing a new boot loader into the Arduino Mega by using a Arudino Uno as an ISP programmer as shown in these links.  Use the following boot loader:

hardware/arduino/bootloader/stk500v2/stk500boot_v2_mega2560.hex

The new boot loader image we used was in the Arduino directory.  If you are on a Mac, open up the app bundle in Finder.

This fixed our problem, but still with a verification error, but the boot loader is working and we can program the Mega again.  (note: We suspect the following will remove the verification error, but we haven't tested it yet:  disable the -D command to auto erase the chip and add the -e instead.)


We used the tutorial on:

http://arduino.cc/en/Tutorial/ArduinoISP 


for the IDE procedure.

Remember that the pins to be used changed from the Uno to the Mega, so use the following wiring diagram:



UNO to Mega pins

Arduino Uno      Target Mega2560

D10 (SS)            Reset
D11 (MOSI)          D51
D12 (MISO)          D50
D13 (SCK)           D52

Gnd                 Gnd
+5V                 +5V


Now the Arduino is working fine in the system.  Here is a picture from the RasPiConnect App (www.milocreek.com) of the functioning Arduino system.

Arduino Based Battery Watchdog


Picture of the location of Project Curacao

Tuesday, November 26, 2013

RasPiConnect Configuration File and Screens Posted


The latest RasPiConnect configuration file and pictures of all five control screens have been posted on the page RasPiConnect Page.  This should answer some of the questions submitted via email.


Monday, November 25, 2013

Current Software and Reliability Issues in Project Curacao


As we get closer to system deployment (March 2014), I am running more system level tests.  The first of these (the week of November 17-24) revealed the following problems that need to be addressed:

- The DHT22 sensor is returning more errors that it should and those errors are getting logged as good data.  Either we aren't using the checksum correctly or the sensor is actually sending bad data in which case we will put a software filter on the output.  See the spikes in the following picture from RasPiConnect:
DHT22 Humidity Bad Data Spikes



Note the windspeed chart.  We are adding a pitot tube windspeed indicator to our environmental subsystem in the next few weeks.


- We are experiencing occasional failures in sending email from ProjectCuracao outside of the systems.   In one case (the initial Reboot and startup email) it is not in a separate thread so it takes the whole Project Curacao main software down when it bombs.  We have good log information so we should be able to track this down.  We will put in Try/Recover blocks, but we'd still like to see what is causing the problem.

- After three days on the Pi, the Project Curacao system is failing because we can't open any more files.  We installed "lsof" on the Pi and we are tracking this down.   This is a lower priority bug at this point because the BatteryWatchdog will shut down the Pi on a daily basis in any case.  Some where, someone is not shutting a file that has been opened and they accumulate.

We swapped out a LiPo Rider Pro board that seemed to have a problem with charging the Watchdog battery properly.  It was discharging and charging in a much different manner than the charge controller for the Pi.  We'll know in a couple of days whether it works properly.




Software Status on Project Curacao (11/25/13)

As of today, the current state of the software in Project Curacao is as follows:

- Arduino Battery Watchdog:  The watchdog is reading and reporting data back to the main software in the Pi via a serial link through level shifters.  The read fails occasionally (and is logged on the Pi) but not often enough to worry about at this point.  The next three things to be implemented:


  1.  Pi power control - The Arduino switching the Pi on and off according to power and time criteria.  Right now the "action" code is commented out and just prints "Pi On" or "Pi Off" to the serial port
  2. Watchdog logging - the Arduino will log major events in EEPROM and then transmit the log, when asked, to the Pi for storage
  3. The Watchdog function - The Arduino will listen for a WD input from the Pi every 5 minutes.  If the Pi misses three sends in a row, the Arduino will send a Reboot command to the Pi and the power cycle the Pi.

- Project Curacao Pi main program:  The main program is generating all the graphs, camera pictures, environment sensing as required.  It is also regulating the Fan automatically now.  Not sending Watchdog to the BatteryWatchdog yet.  Nor reading log files from the Arduino Watchdog.  Next three things to be implemented:

  1. Watchdog implementation
  2. Logging Arduino Watchdog Data
  3. Improving sensor error detection




- RasPiConnect:  We have a few more graphs and dials and buttons to implement on the RasPiConnect software, but it's pretty close to final.  We use this all the time now to monitor what is going on in the project remotely.   We are thinking it might be good to put in a process monitor graph and reboot function.  Both are easily done.  Here's the new main screen (1 of 6 at this point).:


Summary Page for Project Curacao on RasPiConnect




Friday, November 15, 2013

Measuring negative currents with the INA219

I read somewhere that the Adafruit C++ library has a bug in the INA219 High Side current measuring device library so the device doesn't correctly return negative values for current.

Obviously, for a solar power system, I need to measure negative currents (current goes both out of and into the battery- when charging). I ran across this problem a couple of months ago and figured it out. I was using the Subfact Python library for the INA219.


There is also a similar bug in the subfact python library as in the Adafruit C++ library for the INA219 (fixed as of November 2013). They aren't calculating twos complement correctly, so negative currents aren't reported correctly.

The ProjectCuracao unit is plugged in at moment to a USB charger, hence the funny looking efficiency numbers. On my RasPiConnect control screen, you can clearly see the -6ma heading into the battery.  Special thanks to "faraday" for finding the same issue and contributing to the fix.





Heres are the fixes for the subfact python library for the INA219.:


def twosToInt( val, len):
      # Convert twos compliment to integer

      if(val & (1 << len - 1)):

         val = val - (1<<len)

      return val




Changes to subfact python library:


        def getShuntVoltage_raw(self):

                result = self.i2c.readList(self.__INA219_REG_SHUNTVOLTAGE,2)
                if (result[0] >> 7 == 1):
                        testint = (result[0]*256 + result[1])
                        othernew = twosToInt( testint, 16)
                        return othernew
                else:
                        return (result[0] << 8) | (result[1])


        def getCurrent_raw(self):

                result = self.i2c.readList(self.__INA219_REG_CURRENT,2)
                 if (result[0] >> 7 == 1):
                        testint = (result[0]*256 + result[1])
                        othernew = twosToInt( testint, 16)
                        return othernew
                else:
                        return (result[0] << 8) | (result[1])

        def getPower_raw(self):

                result = self.i2c.readList(self.__INA219_REG_POWER,2)
                if (result[0] >> 7 == 1):
                        testint = (result[0]*256 + result[1])
                        othernew = twosToInt( testint, 16)
                        return othernew
                else:
                        return (result[0] << 8) | (result[1])

Thursday, November 14, 2013

Project Curacao Added

Today I have posted the first of six articles describing my current "obsession", Project Curacao.  This is a solar powered environmental monitoring box based on a Raspberry Pi and Arduino Mega 2650 controlled by the iPhone/iPad app RasPiConnect.   It will be hung on a amateur radio tower in Curacao in March of 2014.  It is close to be being finished and will go through system testing for January and February of 2014.


The Project Curacao Box as of as of November 3, 2013



















The first prototype and connection to RasPiConnect in February 2013




















I have learned a lot about the current state of inexpensive computers, inexpensive sensors and prototyping techniques.  I've been using embedded systems for close to thirty years, but for an entire decade I was involved with Wastewater Treatment, Computer Security and Medical Software.  Time to get up to date with the current technology.

I'll share all the problems as well as the successes.  Leave a comment if you have learned something good here or want to ask a question.

Welcome

Welcome to Switch, Blog of the stars.  Well, of the geeks anyway.

I will be posting my thoughts about technology, geekness and music here periodically.  I also will be reposting articles I have written and expand upon them.