Skip to content

Commit e604ee8

Browse files
committed
Merge branch 'main' into add-bmp581
2 parents e6fc230 + 9b79afc commit e604ee8

File tree

5 files changed

+186
-9
lines changed

5 files changed

+186
-9
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306
10+
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit AS5600 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306

platformio.ini

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ lib_deps =
3232
adafruit/ENS160 - Adafruit Fork
3333
adafruit/Adafruit SleepyDog Library
3434
adafruit/Adafruit AHTX0
35+
adafruit/Adafruit AS5600 Library
3536
adafruit/Adafruit BME280 Library
3637
adafruit/Adafruit BMP280 Library
3738
adafruit/Adafruit BMP3XX Library
@@ -205,6 +206,7 @@ board_build.partitions = min_spiffs.csv
205206
extends = common:esp32
206207
board = featheresp32-s2
207208
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2 -DBOARD_HAS_PSRAM
209+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
208210
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
209211
extra_scripts = pre:rename_usb_config.py
210212

@@ -213,6 +215,7 @@ extra_scripts = pre:rename_usb_config.py
213215
extends = common:esp32
214216
board = adafruit_feather_esp32s2_tft
215217
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT -DBOARD_HAS_PSRAM
218+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
216219
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
217220
extra_scripts = pre:rename_usb_config.py
218221

@@ -221,6 +224,7 @@ extra_scripts = pre:rename_usb_config.py
221224
extends = common:esp32
222225
board = adafruit_feather_esp32s2_reversetft
223226
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_REVTFT -DBOARD_HAS_PSRAM
227+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
224228
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
225229
extra_scripts = pre:rename_usb_config.py
226230

@@ -229,7 +233,7 @@ extra_scripts = pre:rename_usb_config.py
229233
extends = common:esp32
230234
board = adafruit_feather_esp32s3
231235
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3 -DBOARD_HAS_PSRAM
232-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
236+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
233237
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
234238
extra_scripts = pre:rename_usb_config.py
235239

@@ -248,7 +252,7 @@ build_type = debug
248252
debug_tool = esp-builtin
249253
board = adafruit_feather_esp32s3_tft
250254
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT -DBOARD_HAS_PSRAM
251-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
255+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
252256
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
253257
extra_scripts = pre:rename_usb_config.py
254258

@@ -257,7 +261,7 @@ extra_scripts = pre:rename_usb_config.py
257261
extends = common:esp32
258262
board = adafruit_feather_esp32s3_reversetft
259263
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_REVTFT -DBOARD_HAS_PSRAM
260-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
264+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
261265
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
262266
extra_scripts = pre:rename_usb_config.py
263267

@@ -266,7 +270,7 @@ extra_scripts = pre:rename_usb_config.py
266270
extends = common:esp32
267271
board = adafruit_magtag29_esp32s2
268272
build_flags = -DARDUINO_MAGTAG29_ESP32S2 -DBOARD_HAS_PSRAM
269-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
273+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
270274
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
271275
extra_scripts = pre:rename_usb_config.py
272276

@@ -275,9 +279,12 @@ extra_scripts = pre:rename_usb_config.py
275279
extends = common:esp32
276280
board = adafruit_metro_esp32s2
277281
build_flags = -DARDUINO_METRO_ESP32S2 -DBOARD_HAS_PSRAM
278-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
282+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
279283
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
280284
extra_scripts = pre:rename_usb_config.py
285+
; debug_tool = jlink
286+
; upload_protocol = jlink
287+
; debug_init_break = tbreak WipperSnapper_I2C_Driver_MLX90632D
281288

282289
; Adafruit Metro ESP32-S3
283290
[env:adafruit_metro_esp32s3]
@@ -287,13 +294,14 @@ build_flags = -DARDUINO_METRO_ESP32S3 -DBOARD_HAS_PSRAM
287294
;set partition to tinyuf2-partitions-16MB.csv as of idf 5.1
288295
board_build.partitions = tinyuf2-partitions-16MB.csv
289296
extra_scripts = pre:rename_usb_config.py
297+
debug_tool = jlink
290298

291299
; Adafruit Funhouse ESP32-S2
292300
[env:adafruit_funhouse_esp32s2]
293301
extends = common:esp32
294302
board = adafruit_funhouse_esp32s2
295303
build_flags = -DARDUINO_FUNHOUSE -DBOARD_HAS_PSRAM
296-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
304+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
297305
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
298306
extra_scripts = pre:rename_usb_config.py
299307

@@ -322,7 +330,7 @@ build_flags =
322330
-DLV_LOG_PRINTF=1
323331
-DLV_LOG_COLOR=1
324332
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
325-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
333+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
326334
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
327335
extra_scripts = pre:rename_usb_config.py
328336

@@ -364,7 +372,7 @@ board_build.partitions = min_spiffs.csv
364372
extends = common:esp32
365373
board = adafruit_qtpy_esp32s2
366374
build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S2 -DBOARD_HAS_PSRAM
367-
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
375+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
368376
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
369377
extra_scripts = pre:rename_usb_config.py
370378

@@ -381,12 +389,14 @@ extra_scripts = pre:rename_usb_config.py
381389
extends = common:esp32
382390
board = adafruit_qtpy_esp32s3_n4r2
383391
build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2 -DBOARD_HAS_PSRAM
392+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
384393
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
385394
extra_scripts = pre:rename_usb_config.py
386395

387396
[env:adafruit_qtpy_esp32s3_with_psram_debug]
388397
extends = common:esp32
389398
board = adafruit_qtpy_esp32s3_n4r2
399+
;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10
390400
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
391401
build_type = debug
392402
build_flags =

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
236236
}
237237
_ahtx0->configureDriver(msgDeviceInitReq);
238238
drivers.push_back(_ahtx0);
239+
} else if (strcmp("as5600", msgDeviceInitReq->i2c_device_name) == 0) {
240+
_as5600 = new WipperSnapper_I2C_Driver_AS5600(this->_i2c, i2cAddress);
241+
if (!_as5600->begin()) {
242+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize AS5600 chip!");
243+
_busStatusResponse =
244+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
245+
return false;
246+
}
247+
_as5600->configureDriver(msgDeviceInitReq);
248+
drivers.push_back(_as5600);
239249
} else if (strcmp("bh1750", msgDeviceInitReq->i2c_device_name) == 0) {
240250
_bh1750 = new WipperSnapper_I2C_Driver_BH1750(this->_i2c, i2cAddress);
241251
if (!_bh1750->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "drivers/WipperSnapper_I2C_Driver.h"
2323
#include "drivers/WipperSnapper_I2C_Driver_ADT7410.h"
2424
#include "drivers/WipperSnapper_I2C_Driver_AHTX0.h"
25+
#include "drivers/WipperSnapper_I2C_Driver_AS5600.h"
2526
#include "drivers/WipperSnapper_I2C_Driver_BH1750.h"
2627
#include "drivers/WipperSnapper_I2C_Driver_BME280.h"
2728
#include "drivers/WipperSnapper_I2C_Driver_BME680.h"
@@ -159,6 +160,7 @@ class WipperSnapper_Component_I2C {
159160
_drivers_out; ///< List of i2c output drivers
160161
// Sensor driver objects
161162
WipperSnapper_I2C_Driver_AHTX0 *_ahtx0 = nullptr;
163+
WipperSnapper_I2C_Driver_AS5600 *_as5600 = nullptr;
162164
WipperSnapper_I2C_Driver_D6T1A *_d6t1a = nullptr;
163165
WipperSnapper_I2C_Driver_DPS310 *_dps310 = nullptr;
164166
WipperSnapper_I2C_Driver_DS2484 *_ds2484 = nullptr;
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_AS5600.h
3+
*
4+
* Device driver for the AS5600 Magnetic Angle sensor.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2024 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WipperSnapper_I2C_Driver_AS5600_H
16+
#define WipperSnapper_I2C_Driver_AS5600_H
17+
18+
#include <Adafruit_AS5600.h>
19+
20+
#include "WipperSnapper_I2C_Driver.h"
21+
#include "Wippersnapper.h"
22+
23+
/**************************************************************************/
24+
/*!
25+
@brief Class that provides a driver interface for a AS5600 sensor.
26+
*/
27+
/**************************************************************************/
28+
class WipperSnapper_I2C_Driver_AS5600 : public WipperSnapper_I2C_Driver {
29+
public:
30+
/*******************************************************************************/
31+
/*!
32+
@brief Constructor for the AS5600 sensor.
33+
@param i2c
34+
The I2C interface.
35+
@param sensorAddress
36+
7-bit device address.
37+
*/
38+
/*******************************************************************************/
39+
WipperSnapper_I2C_Driver_AS5600(TwoWire *i2c, uint16_t sensorAddress)
40+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
41+
_as5600 = nullptr;
42+
_angle = 0;
43+
}
44+
45+
/*******************************************************************************/
46+
/*!
47+
@brief Destructor for an AS5600 sensor.
48+
*/
49+
/*******************************************************************************/
50+
~WipperSnapper_I2C_Driver_AS5600() {
51+
if (_as5600) {
52+
delete _as5600;
53+
_as5600 = nullptr;
54+
}
55+
}
56+
57+
/*******************************************************************************/
58+
/*!
59+
@brief Initializes the AS5600 sensor and begins I2C.
60+
@returns True if initialized successfully, False otherwise.
61+
*/
62+
/*******************************************************************************/
63+
bool begin() {
64+
_as5600 = new Adafruit_AS5600();
65+
if (!_as5600->begin((uint8_t)_sensorAddress, _i2c)) {
66+
WS_DEBUG_PRINTLN("Failed to find AS5600 chip");
67+
return false;
68+
}
69+
70+
if (!configureSensor()) {
71+
WS_DEBUG_PRINTLN("Failed to configure AS5600 sensor");
72+
return false;
73+
}
74+
return true;
75+
}
76+
77+
/*******************************************************************************/
78+
/*!
79+
@brief Configures the AS5600 sensor.
80+
@returns True if the sensor was configured successfully, False otherwise.
81+
*/
82+
/*******************************************************************************/
83+
bool configureSensor() {
84+
return _as5600->enableWatchdog(false) &&
85+
// Normal (high) power mode
86+
_as5600->setPowerMode(AS5600_POWER_MODE_NOM) &&
87+
// No Hysteresis
88+
_as5600->setHysteresis(AS5600_HYSTERESIS_OFF) &&
89+
// analog output (0-VCC for 0-360 degrees)
90+
_as5600->setOutputStage(AS5600_OUTPUT_STAGE_ANALOG_FULL) &&
91+
// setup filters
92+
_as5600->setSlowFilter(AS5600_SLOW_FILTER_16X) &&
93+
_as5600->setFastFilterThresh(AS5600_FAST_FILTER_THRESH_SLOW_ONLY) &&
94+
// Reset position settings to defaults
95+
_as5600->setZPosition(0) && _as5600->setMPosition(4095) &&
96+
_as5600->setMaxAngle(4095);
97+
}
98+
99+
/*******************************************************************************/
100+
/*!
101+
@brief Reads the Angle sensor.
102+
@returns True if the sensor was read successfully, False otherwise.
103+
*/
104+
/*******************************************************************************/
105+
bool readSensor() {
106+
if (!_as5600->isMagnetDetected()) {
107+
WS_DEBUG_PRINTLN("Magnet not detected!");
108+
return false;
109+
}
110+
111+
// Continuously read and display angle values
112+
uint16_t rawAngle = _as5600->getRawAngle();
113+
uint16_t angle = _as5600->getAngle();
114+
115+
WS_DEBUG_PRINT("AS5600 Raw: ");
116+
WS_DEBUG_PRINT(rawAngle);
117+
WS_DEBUG_PRINT(" | Scaled: ");
118+
WS_DEBUG_PRINT(angle);
119+
120+
// Check status conditions
121+
if (_as5600->isAGCminGainOverflow()) {
122+
WS_DEBUG_PRINTLN(" | MH: magnet too strong");
123+
return false;
124+
}
125+
if (_as5600->isAGCmaxGainOverflow()) {
126+
WS_DEBUG_PRINTLN(" | ML: magnet too weak");
127+
return false;
128+
}
129+
_angle = ((float)angle / 4095.0) * 360.0;
130+
return true;
131+
}
132+
133+
/*******************************************************************************/
134+
/*!
135+
@brief Reads the Angle sensor with short wait for data.
136+
@param rawEvent
137+
Angle sensor reading
138+
@returns True if the sensor event was obtained successfully, False
139+
otherwise.
140+
*/
141+
/*******************************************************************************/
142+
bool getEventRaw(sensors_event_t *rawEvent) {
143+
if (!readSensor()) {
144+
return false;
145+
}
146+
rawEvent->data[0] = _angle;
147+
return true;
148+
}
149+
150+
protected:
151+
float _angle; ///< Current angle reading from the AS5600 sensor
152+
Adafruit_AS5600 *_as5600; ///< Pointer to AS5600 sensor object
153+
};
154+
155+
#endif // WipperSnapper_I2C_Driver_AS5600

0 commit comments

Comments
 (0)