From 997631fc8895d303779850e55a5b038b44848b33 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 14:11:46 -0400 Subject: [PATCH 1/4] initial add --- afsk/Adafruit_INA219.h | 154 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 afsk/Adafruit_INA219.h diff --git a/afsk/Adafruit_INA219.h b/afsk/Adafruit_INA219.h new file mode 100644 index 00000000..1e8c0c63 --- /dev/null +++ b/afsk/Adafruit_INA219.h @@ -0,0 +1,154 @@ +/*! + * @file Adafruit_INA219.h + * + * This is a library for the Adafruit INA219 breakout board + * ----> https://www.adafruit.com/products/904 + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Written by Kevin "KTOWN" Townsend for Adafruit Industries. + * + * BSD license, all text here must be included in any redistribution. + * + * Converted to C for Raspberry Pi by Alan Johnston KU2Y + * + */ + +#include + +/** default I2C address **/ +#define INA219_ADDRESS (0x40) // 1000000 (A0+A1=GND) + +/** read **/ +#define INA219_READ (0x01) + +/*========================================================================= + CONFIG REGISTER (R/W) +**************************************************************************/ + +/** config register address **/ +#define INA219_REG_CONFIG (0x00) + +/** reset bit **/ +#define INA219_CONFIG_RESET (0x8000) // Reset Bit + +/** mask for bus voltage range **/ +#define INA219_CONFIG_BVOLTAGERANGE_MASK (0x2000) // Bus Voltage Range Mask + +/** bus voltage range values **/ +enum { + INA219_CONFIG_BVOLTAGERANGE_16V = (0x0000), // 0-16V Range + INA219_CONFIG_BVOLTAGERANGE_32V = (0x2000), // 0-32V Range +}; + +/** mask for gain bits **/ +#define INA219_CONFIG_GAIN_MASK (0x1800) // Gain Mask + +/** values for gain bits **/ +enum { + INA219_CONFIG_GAIN_1_40MV = (0x0000), // Gain 1, 40mV Range + INA219_CONFIG_GAIN_2_80MV = (0x0800), // Gain 2, 80mV Range + INA219_CONFIG_GAIN_4_160MV = (0x1000), // Gain 4, 160mV Range + INA219_CONFIG_GAIN_8_320MV = (0x1800), // Gain 8, 320mV Range +}; + +/** mask for bus ADC resolution bits **/ +#define INA219_CONFIG_BADCRES_MASK (0x0780) + +/** values for bus ADC resolution **/ +enum { + INA219_CONFIG_BADCRES_9BIT = (0x0000), // 9-bit bus res = 0..511 + INA219_CONFIG_BADCRES_10BIT = (0x0080), // 10-bit bus res = 0..1023 + INA219_CONFIG_BADCRES_11BIT = (0x0100), // 11-bit bus res = 0..2047 + INA219_CONFIG_BADCRES_12BIT = (0x0180), // 12-bit bus res = 0..4097 +}; + +/** mask for shunt ADC resolution bits **/ +#define INA219_CONFIG_SADCRES_MASK \ + (0x0078) // Shunt ADC Resolution and Averaging Mask + +/** values for shunt ADC resolution **/ +enum { + INA219_CONFIG_SADCRES_9BIT_1S_84US = (0x0000), // 1 x 9-bit shunt sample + INA219_CONFIG_SADCRES_10BIT_1S_148US = (0x0008), // 1 x 10-bit shunt sample + INA219_CONFIG_SADCRES_11BIT_1S_276US = (0x0010), // 1 x 11-bit shunt sample + INA219_CONFIG_SADCRES_12BIT_1S_532US = (0x0018), // 1 x 12-bit shunt sample + INA219_CONFIG_SADCRES_12BIT_2S_1060US = + (0x0048), // 2 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_4S_2130US = + (0x0050), // 4 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_8S_4260US = + (0x0058), // 8 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_16S_8510US = + (0x0060), // 16 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_32S_17MS = + (0x0068), // 32 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_64S_34MS = + (0x0070), // 64 x 12-bit shunt samples averaged together + INA219_CONFIG_SADCRES_12BIT_128S_69MS = + (0x0078), // 128 x 12-bit shunt samples averaged together +}; + +/** mask for operating mode bits **/ +#define INA219_CONFIG_MODE_MASK (0x0007) // Operating Mode Mask + +/** values for operating mode **/ +enum { + INA219_CONFIG_MODE_POWERDOWN, + INA219_CONFIG_MODE_SVOLT_TRIGGERED, + INA219_CONFIG_MODE_BVOLT_TRIGGERED, + INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED, + INA219_CONFIG_MODE_ADCOFF, + INA219_CONFIG_MODE_SVOLT_CONTINUOUS, + INA219_CONFIG_MODE_BVOLT_CONTINUOUS, + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS +}; + +/** shunt voltage register **/ +#define INA219_REG_SHUNTVOLTAGE (0x01) + +/** bus voltage register **/ +#define INA219_REG_BUSVOLTAGE (0x02) + +/** power register **/ +#define INA219_REG_POWER (0x03) + +/** current register **/ +#define INA219_REG_CURRENT (0x04) + +/** calibration register **/ +#define INA219_REG_CALIBRATION (0x05) + +/*! + * functions for interacting with INA219 + * current/power monitor IC + */ + //void begin(TwoWire *theWire = &Wire); + void setCalibration_32V_2A(int fd); + void setCalibration_32V_1A(int fd); + void setCalibration_16V_400mA(int fd); + void setCalibration_16V_2A(int fd); + float getBusVoltage_V(int fd); + float getShuntVoltage_mV(int fd); + float getCurrent_mA(int fd); + float getPower_mW(int fd); + void powerSave(int fd, int on); + + uint8_t ina219_i2caddr; + //uint32_t ina219_calValue; + uint16_t ina219_calValue; + uint16_t ina219_config; + // The following multipliers are used to convert raw current and power + // values to mA and mW, taking into account the current config settings + uint32_t ina219_currentDivider_mA; + float ina219_powerMultiplier_mW; + + void init(); + void wireWriteRegister(int fd, uint8_t reg, uint16_t value); + uint16_t wireReadRegister(int fd, uint8_t reg); + int16_t getBusVoltage_raw(int fd); + int16_t getShuntVoltage_raw(int fd); + int16_t getCurrent_raw(int fd); + int16_t getPower_raw(int fd); From 4018f396aef4bd746fc0b8e50a58836e1da5c984 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 14:14:02 -0400 Subject: [PATCH 2/4] moving location of Adafruit_INA219.h --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index bfd86ffa..2f4f6860 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,7 +35,7 @@ #include #include #include -#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #define A 1 #define B 2 From 63af9ad620e634605ca9fccb78112f15cc21329d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 14:15:02 -0400 Subject: [PATCH 3/4] moved Adafruit_INA219.h --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 56e9778f..96f6c244 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -33,7 +33,7 @@ #include #include #include -#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #define A 1 #define B 2 From e7d21ccb93682cc099698a3ddf99f587ba02d2d3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 14:20:59 -0400 Subject: [PATCH 4/4] added requirements of git, wiringpi, and libcurl --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d9367e2f..dbd30aa7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ The CubeSat Simulator https://github.com/alanbjohnston/CubeSatSim/wiki is a low cost satellite emulator that run on solar panels and batteries, transmits UHF radio telemetry, has a 3D printed frame, and can be extended by additional sensors and modules. This project is sponsored by the not-for-profit [Radio Amateur Satellite Corporation, AMSATĀ®](https://amsat.org). +Requires: +- wiringpi +- libcurl4-openssl-dev +- git + See the Wiki Software Install page for more details: https://github.com/alanbjohnston/CubeSatSim/wiki/Software-Install. To build and run the software on a Raspberry Pi 3B, 3B+, or Pi Zero W: `git clone http://github.com/alanbjohnston/CubeSatSim.git` @@ -12,15 +17,11 @@ Edit the afsk/main.c file to set your amateur radio callsign, then `make rebuild` -To hear CW telemetry (Morse code), tune your radio or SDR to 435.297 MHz and enter: - -`./radiocw` - -To stop, Ctrl-C. To hear AFSK telemetry (X.25 data), your radio or SDR to 440.389 MHz FM, and you should receive telemetry from the CubeSat Sim: +To hear AFSK telemetry (X.25 data), your radio or SDR to 434.9 MHz FM, and you should receive telemetry from the CubeSat Sim: `./radioafsk` -This code uses the Brandenburg Tech Digital Transceiver, based on DigitalTxRxRP https://brandenburgtech.wordpress.com/ +This code uses the Brandenburg Tech Digital Transceiver, based on DigitalTxRxRP https://brandenburgtech.wordpress.com/ If you don't have the SPI Interface enabled and the board plugged in, you will get an error. This repository contains: