Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ads101x #854

Merged
merged 2 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,93 +636,94 @@ you specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ad7928">AD7928</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-adis16470">ADIS16470</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-adns9800">ADNS9800</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads101x">ADS101X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads7843">ADS7843</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads816x">ADS816x</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ads816x">ADS816x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ams5915">AMS5915</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-apa102">APA102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-block-device-spi-flash">SPI Flash</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bme280">BME280</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bmp085">BMP085</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1302">DS1302</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">Encoder Input</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">Encoder Output BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31855">MAX31855</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr>
</table>
Expand Down
179 changes: 179 additions & 0 deletions examples/nucleo_g474re/ads101x/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// coding: utf-8
/*
* Copyright (c) 2022, Jonas Kazem Andersen
* Copyright (c) 2022, Rasmus Kleist Hørlyck Sørensen
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <modm/driver/adc/ads101x.hpp>

using Scl = modm::platform::GpioC6;
using Sda = modm::platform::GpioC7;
using I2cMaster = modm::platform::I2cMaster4;

using namespace Board;

class AdcThread : public modm::pt::Protothread
{

public:
AdcThread() : adc(data)
{
}

inline bool
run()
{
PT_BEGIN();

// test of communication and initialization
while (not PT_CALL(adc.ping()))
{
MODM_LOG_ERROR << "Pinging Ads101x failed" << modm::endl;

shortTimeout.restart(std::chrono::milliseconds(1000));
PT_WAIT_UNTIL(shortTimeout.isExpired());
}

while (not PT_CALL(adc.initialize()))
{
MODM_LOG_ERROR << "Initialising Ads101x failed" << modm::endl;

shortTimeout.restart(std::chrono::milliseconds(1000));
PT_WAIT_UNTIL(shortTimeout.isExpired());
}

MODM_LOG_INFO << "Ads101x successfully initialised" << modm::endl;

while (true)
{
// Single shot and full scale range test
MODM_LOG_INFO << "Started single conversion test" << modm::endl;
timeout.restart(std::chrono::seconds(10));
while (not timeout.isExpired())
{
// Test single shoot mode with full scale range 0.256
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V0_256));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 0.256V: " << data.getVoltage() << modm::endl;

// Test single shoot mode with full scale range 0.512
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V0_512));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 0.512V: " << data.getVoltage() << modm::endl;

// Test single shoot mode with full scale range 1.024
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V1_024));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 1.024V: " << data.getVoltage() << modm::endl;

// Test single shoot mode with full scale range 2.048
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V2_048));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 2.048V: " << data.getVoltage() << modm::endl;

// Test single shoot mode with full scale range 4.096
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V4_096));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 4.096V: " << data.getVoltage() << modm::endl;

// Test single shoot mode with full scale range 6.144
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V6_144));
PT_CALL(adc.startSingleShotConversion(modm::ads101x::InputMultiplexer::Input4));
while (PT_CALL(adc.isBusy()))
{
PT_YIELD();
}

PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Single Conversion result in range 6.144V: " << data.getVoltage() << modm::endl;

shortTimeout.restart(std::chrono::milliseconds(1000));
PT_WAIT_UNTIL(shortTimeout.isExpired());
}

// Continuous mode test
MODM_LOG_INFO << "Started continuous conversion test" << modm::endl;
PT_CALL(adc.setFullScaleRange(modm::ads101x::FullScaleRange::V6_144));
PT_CALL(adc.startContinuousConversion(modm::ads101x::InputMultiplexer::Input4));

timeout.restart(std::chrono::seconds(10));
while (not timeout.isExpired())
{
shortTimeout.restart(std::chrono::milliseconds(1000));
PT_WAIT_UNTIL(shortTimeout.isExpired());
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO << "Continuous Conversion result in range 6.144V: " << data.getVoltage() << modm::endl;
}
}
PT_END();
}

private:
modm::ads101x::Data data;
modm::Ads101x<I2cMaster> adc;

modm::Timeout timeout;
modm::ShortTimeout shortTimeout;

} adcThread;

int
main()
{
Board::initialize();

I2cMaster::connect<Scl::Scl, Sda::Sda>(I2cMaster::PullUps::Internal);
I2cMaster::initialize<Board::SystemClock, 100_kHz>();

MODM_LOG_INFO << "==========ADS101x Test==========" << modm::endl;
MODM_LOG_DEBUG << "Debug logging here" << modm::endl;
MODM_LOG_INFO << "Info logging here" << modm::endl;
MODM_LOG_WARNING << "Warning logging here" << modm::endl;
MODM_LOG_ERROR << "Error logging here" << modm::endl;
MODM_LOG_INFO << "===============================" << modm::endl;

while (true)
{
adcThread.run();
}

return 0;
}
14 changes: 14 additions & 0 deletions examples/nucleo_g474re/ads101x/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<library>
<extends>modm:nucleo-g474re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g474re/ads101x</option>
</options>
<modules>
<module>modm:driver:ads101x</module>
<module>modm:platform:gpio</module>
<module>modm:platform:i2c:4</module>
<module>modm:processing:protothread</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
</modules>
</library>
Loading