Table of Contents

Firmware - User Manual

The firmware for the weatherbox project is modular platform-agnostic program. It is designed to be versatile in the sense that it can be easily adapted for any changes to the current generations, without affecting the processes of another generation and to be modular enough to support implementation of new generations and hardware. This page is designed to aid the maintenance and development of the firmware.


Necessary Tools


Modules

The firmware code is broken into four main modules:

  1. Configuration Module
  2. Sensor Module
  3. Transmit Module
  4. Utility Module

These modules are designed in a way such that they're independent of each other for lower level testing purposes. When the dependencies are put into place (i.e. the Transmit module calls functions from the Sensor module), they can also be tested incrementally. The only major dependence is in the Configuration Module when testing the other modules on a particular generation.


Configuration Module

This module controls what generation the firmware is being run on. It handles the necessary pin configurations and function pointer assignments.

Pin Changes

Generation Configuration

New Generation

New Function Pointers

Generation Version Updates


Sensor Module

This module contains the functions that initialize and poll data from the sensors. For the newer generations, it uses the I2C line, so knowing the addresses of the components is important. The I2C addresses of a component can be found in their data sheets.

Sensor Libraries

Scaling Factors

I2C

Objects


Transmit Module

This module contains the necessary functions for transmissions. This includes clearing/initializing the packets, filling the packet with data, transferring the packet into a payload, and transmitting the payload. Relies on the XBee library.

Transmission Methods

XBee Configurations

Test Functions

New Transmission Methods

Globals

Objects

Schema


Utility Module

This module provides miscellaneous functions that the other modules might need. It also includes all the macro definitions such as constants, voltage thresholds, and true/false macros. It also includes various health functions and power management functions that manage the health and mode of operation for the weatherbox. Low pass filter functions are also included here.

Macro Definitions

Health Management

Power Management

Low Pass Filter


Updating Protocol

When updating the Firmware certain procedures must be taken into account to ensure conflicts don't occur and the changes in modules are reflecting in the main Firmware directory and vice versa.

  1. Always do a pull from your test branch before working on code
  2. Always test compile and/or test with hardware after any changes are implemented
  3. Always commit your changes with meaningful comments
  4. Always push your commits before you stop working
  5. Never work directly off the master branch
  6. Follow the same commenting syntax for new functions

Notice the following (about the master branch):


Branches

Work off of particular branches or create a new branch when doing an update.

New Branch:

When creating a new branch, make sure that it is branched off of the code contained in master and not off of another branch.

Naming:

Completion:

Submit a pull request to master when the feature is completed, tested, and verified.


Module Changes


Generation Testing

Verifying that the code compiles does not necessarily mean that it will work as intended. Each module should be tested on each generation to validate its functionality. However, testing each individual module and confirming that they work separately, does not confirm that the modules will work together. Therefore we must also test full integration with each generation, the most important test before deployment.


Sensor Module Test

Apple

Necessary Components:

Test Environment:

  1. Connect the Apple board to the computer using the USB
  2. In Arduino IDE, under Tools check:
    • Board is set to Arduino UNO
    • Port is set to the specific USB port that the programmer is plugged into
    • Programmer is set to AVRISP mkII
  3. In config.h verify that only macro “APPLE” is defined
  4. Run a test compile to ensure libraries are found and no compile-time errors occur
  5. Upload program to board

Expected Results (Inside SCEL room):

  1. Once the upload is complete, open the Serial Monitor (Ctrl+Shift+M)
  2. Sensor readings will appear here every ~6 seconds
  3. Use the floodlight to verify that solar irradiance and temperature vary (humidity may be affected as well)
  4. Readings:
    • Battery mV = ~4095 (Compare to battery source level)
    • Solar Irr mV = ~5000 (Depends on floodlight intensity)
    • Humidity pct = ~50 (Depends on floodlight intensity, and weather)
    • Panel mV = ~6000 (Depends on floodlight intensity)
    • Temp decic = ~26 (Compare to actual temperature)
    • Pressure pa = ~101000

Cranberry

Necessary Components:

Test Environment:

Expected Results (Inside SCEL room):

  1. Once the upload is complete, open the Serial Monitor (Ctrl-Shift-M)
  2. Sensor readings will appear here ~every 6 seconds
  3. Use the floodlight to verify that solar irradiance and temperature vary (humidity may be affected as well)
  4. Readings:
    • Battery mV = ~4095 (Compare to battery source level)
    • Solar Irr mV = ~5000 (Depends on floodlight intensity)
    • Humidity pct = ~50 (Depends on floodlight intensity, and weather)
    • Panel mV = ~6000 (Depends on floodlight intensity)
    • Temp decic = ~26 (Compare to actual temperature)
    • Pressure pa = ~101000

Dragon Fruit

Necessary Components:

Test Environment:

Expected Results (Inside SCEL room):

  1. Once the upload is complete, open the Serial Monitor (Ctrl-Shift-M)
  2. Sensor readings will appear here ~every 6 seconds
  3. Use the floodlight to verify that solar irradiance and temperature vary (humidity may be affected as well)
  4. Readings:
    • Battery mV = ~4095 (Compare to battery source level)
    • Solar Irr mV = ~5000 (Depends on floodlight intensity)
    • Humidity pct = ~50 (Depends on floodlight intensity, and weather)
    • Panel mV = ~6000 (Depends on floodlight intensity)
    • Temp decic = ~26 (Compare to actual temperature)
    • Pressure pa = ~101000

Transmit Module Test

Apple

Necessary Components:

Test Environment:

Expected Results:

Cranberry

Necessary Components:

Test Environment:

Expected Results:

Dragon Fruit

Necessary Components:

Test Environment:

Expected Results:


Full Integration Test

This test should only be done once both the sensor module and transmit modules tests have been completed and the results verified. This also assumes that the “burn the bootloader step” has already been executed.

Apple

Necessary Components:

Test Environment:

  1. Plug the battery and the Xbee(Router) into the Apple board
  2. Attach the Xbee(Coordinator) to the Xbee breakout board and plug that into your computer using the USB cable
  3. Open XCTU on your computer
    • Click “Add Device” and select the corresponding USB port that your XBee is plugged into
    • Switch to the “Console” and “Connect” the Xbee to the network
    • Observe the Console log for packets to be received
  4. Connect the Apple board to the computer using the USB
  5. In Arduino IDE, under Tools check:
    • Board is set to Arduino UNO
    • Port is set to the specific USB port that the programmer is plugged into
    • Programmer is set to AVRISP mkII
  6. In config.h verify that only macro “APPLE” is defined
  7. Run a test compile to ensure libraries are found and no compile-time errors occur
  8. Upload program to board

Expected Results:

Cranberry

Necessary Components:

Test Environment:

  1. Plug the battery and the Xbee (Router) into the Cranberry board
  2. Turn on the Cranberry board by flipping the switch to “ON”
  3. Attach the XBee (Coordinator) to the XBee breakout board and plug that into your computer using the USB cable
  4. Open XCTU on your computer
    • Click “Add Device” and select the corresponding USB port that your XBee is plugged into
    • Switch to the “Console” and “Connect” the XBee to the network
    • Observe the Console log for packets to be received
  5. Connect the FTDI programmer to the computer and board
  6. In Arduino IDE, under Tools check:
    • Board is set to Arduino 3.3V 8MHz
    • Port is set to the specific USB port that the programmer plugged into
    • Programmer is set to AVRISP mkII
  7. In config.h verify that only macro “CRANBERRY” is defined
  8. Run a test compile to ensure libraries are found and no compile time errors occur
  9. Upload program to board

Expected Results:

Dragon Fruit

Necessary Components:

Test Environment:

  1. Plug the battery and the XBee (Router) into the Dragon Fruit board
  2. Turn on the Dragon Fruit board by flipping the switch to “ON” (Switch should be flipped towards the battery)
  3. Attach the XBee (Coordinator) to the XBee breakout board and plug that into your computer using the USB cable
  4. Open XCTU on your computer
    • Click “Add Device” and select the corresponding USB port that your XBee is plugged into
    • Switch to the “Console” and “Connect” the XBee to the network
    • Observe the Console log for packets to be received
  5. Connect the FTDI programmer to the computer and board
  6. In Arduino IDE, under Tools check:
    • Board is set to Arduino UNO
    • Port is set to the USB port with the programmer plugged into it
    • Programmer is set to AVRISP mkII
  7. In config.h verify that only macro “DRAGONFRUIT” is defined
  8. Run a test compile to ensure libraries are found and no compile time errors occur
  9. Upload program to board

Expected Results:


Unit Testing & Error Library

Unit testing and the error code library go hand in hand. We will apply unit testing to test and improve each small unit of our firmware. With each test we will have an associated error code that can be used to indicate if that test failed during full operation.


Unit Testing

Unit testing is to examine each unit of the code separately. For our implementation we want to examine the lowest level of each module, the basic function calls. They are not meant to find bugs or detect regressions in the code. These are used to design and develop robust components of our modules.

Designing:

Implementing:

General Notes for Unit Testing


Error Code Library

The Error Code Library will expand off of the unit tests. It does this in such a manner that if the test fails (i.e. the function does something undesirable) an error code will be presented. It can be presented in one of two ways:

  1. In place of a certain sensor data, indicated by being a negative value, when running at a larger scale
  2. Returned from the function with the failed test

Option (1) is for the case of the full integration running, but something goes wrong at one point. This method is to allow the operation of the code to continue, but signifying an error has occurred. Option (2) is for unit testing.

Error Code:

Error Flag:


Authors

Contributing authors:

rwalser scottbn

Created by rwalser on 2016/04/25 08:32.