Skip to content

Commit 1afc27f

Browse files
committed
Adding Pico W AIO and USB Host to BLE project code
Adding Arduino code for two projects: Pico W DVI AIO display and the USB host featherwing to BLE
1 parent 56fd748 commit 1afc27f

6 files changed

Lines changed: 666 additions & 0 deletions

File tree

PicoW_DVI_AIO_Display/.pico_rp2040.test.only

Whitespace-only changes.
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/************************** Configuration ***********************************/
6+
7+
// edit the config.h tab and enter your Adafruit IO credentials
8+
// and any additional configuration needed for WiFi, cellular,
9+
// or ethernet clients.
10+
#include "config.h"
11+
#include "sprites.h"
12+
#include <PicoDVI.h> // Core display & graphics library
13+
#include <Fonts/FreeSansBold18pt7b.h> // A custom font
14+
#include <Fonts/FreeSans9pt7b.h> // A custom font
15+
16+
// put your four feed names here!
17+
18+
AdafruitIO_Feed *temp = io.feed("temperature-feed");
19+
AdafruitIO_Feed *humid = io.feed("humidity-feed");
20+
AdafruitIO_Feed *bat = io.feed("battery-feed");
21+
AdafruitIO_Feed *aqi = io.feed("aqi-feed");
22+
23+
#define IO_LOOP_DELAY 5000
24+
unsigned long lastUpdate = 0;
25+
float temp_data;
26+
float humid_data;
27+
int bat_data;
28+
int aqi_data;
29+
30+
struct outline {
31+
int16_t x, y; // Top-left corner
32+
};
33+
34+
outline greenOutline = {159, 35};
35+
outline yellowOutline = {204, 35};
36+
outline redOutline = {250, 35};
37+
38+
DVIGFX8 display(DVI_RES_320x240p60, false, adafruit_dvibell_cfg);
39+
40+
void setup() {
41+
42+
// start the serial connection
43+
Serial.begin(115200);
44+
45+
// wait for serial monitor to open
46+
//while ( !Serial ) delay(10);
47+
48+
Serial.print("Connecting to Adafruit IO");
49+
50+
// start connection to io.adafruit.com
51+
io.connect();
52+
53+
// set up a message handler for the count feed.
54+
// the handleMessage function (defined below)
55+
// will be called whenever a message is
56+
// received from adafruit io.
57+
temp->onMessage(tempMessage);
58+
humid->onMessage(humidMessage);
59+
bat->onMessage(batMessage);
60+
aqi->onMessage(aqiMessage);
61+
62+
// wait for a connection
63+
while(io.status() < AIO_CONNECTED) {
64+
Serial.print(".");
65+
delay(500);
66+
}
67+
// we are connected
68+
Serial.println();
69+
Serial.println(io.statusText());
70+
71+
// Because Adafruit IO doesn't support the MQTT retain flag, we can use the
72+
// get() function to ask IO to resend the last value for this feed to just
73+
// this MQTT client after the io client is connected.
74+
temp->get();
75+
humid->get();
76+
bat->get();
77+
aqi->get();
78+
79+
Serial.println("starting picodvi..");
80+
if (!display.begin()) { // Blink LED if insufficient RAM
81+
pinMode(LED_BUILTIN, OUTPUT);
82+
for (;;) digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
83+
}
84+
Serial.println("picodvi good to go");
85+
86+
// Set up color palette
87+
display.setColor(0, 0x0000); // black
88+
display.setColor(1, 0x057D); // blue
89+
display.setColor(2, 0xB77F); // light blue
90+
display.setColor(3, 0xE8E4); // red
91+
display.setColor(4, 0x3DA9); // green
92+
display.setColor(5, 0xFF80); // yellow
93+
display.setColor(6, 0xFFFF); // white
94+
95+
}
96+
97+
void loop() {
98+
// io.run(); is required for all sketches.
99+
// it should always be present at the top of your loop
100+
// function. it keeps the client connected to
101+
// io.adafruit.com, and processes any incoming data.
102+
io.run();
103+
104+
if (millis() > (lastUpdate + IO_LOOP_DELAY)) {
105+
display.fillScreen(0);
106+
display.drawBitmap(38, 35, airBitmap, airWidth, airHeight, 2);
107+
display.drawBitmap(47, 132, tempBitmap, tempWidth, tempHeight, 3);
108+
display.drawBitmap(145, 132, waterBitmap, waterWidth, waterHeight, 1);
109+
display.drawBitmap(248, 132, batBitmap, batWidth, batHeight, 6);
110+
drawBatterySquare(bat_data);
111+
displayAQI(aqi_data);
112+
display.setFont(&FreeSansBold18pt7b);
113+
display.setTextColor(6);
114+
display.setCursor(38 + airWidth + 15, 38 + airHeight - 10);
115+
display.println(aqi_data);
116+
display.setFont(&FreeSans9pt7b);
117+
display.setCursor(47 - 9, 130 + tempHeight + 25);
118+
display.print(temp_data, 2);
119+
display.println(" F");
120+
display.setCursor(145 - 9, 130 + tempHeight + 25);
121+
display.print(humid_data, 2);
122+
display.println("%");
123+
display.setCursor(248 - 5, 130 + tempHeight + 25);
124+
display.print(bat_data);
125+
display.println("%");
126+
// store the current time
127+
lastUpdate = millis();
128+
}
129+
130+
}
131+
132+
void humidMessage(AdafruitIO_Data *data) {
133+
//Serial.print("received <- ");
134+
Serial.println(data->value());
135+
String h = data->value();
136+
humid_data = h.toFloat();
137+
}
138+
139+
void tempMessage(AdafruitIO_Data *data) {
140+
//Serial.print("received <- ");
141+
Serial.println(data->value());
142+
String d = data->value();
143+
temp_data = d.toFloat();
144+
}
145+
146+
void batMessage(AdafruitIO_Data *data) {
147+
//Serial.print("received <- ");
148+
Serial.println(data->value());
149+
String b = data->value();
150+
bat_data = b.toInt();
151+
}
152+
153+
void aqiMessage(AdafruitIO_Data *data) {
154+
//Serial.print("received <- ");
155+
Serial.println(data->value());
156+
String a = data->value();
157+
aqi_data = a.toInt();
158+
}
159+
160+
void displayAQI(int data) {
161+
display.fillRoundRect(164, 40, 30, 30, 4, 4);
162+
display.fillRoundRect(209, 40, 30, 30, 4, 5);
163+
display.fillRoundRect(255, 40, 30, 30, 4, 3);
164+
if (data <= 12) { // Good
165+
display.drawRoundRect(greenOutline.x, greenOutline.y, 40, 40, 4, 6);
166+
} else if (data <= 35) { // Bad
167+
display.drawRoundRect(yellowOutline.x, yellowOutline.y, 40, 40, 4, 6);
168+
} else { // Dangerous
169+
display.drawRoundRect(redOutline.x, redOutline.y, 40, 40, 4, 6);
170+
}
171+
}
172+
173+
void drawBatterySquare(int data) {
174+
int BASE_SQUARE_X = 252; // Base X position
175+
int BASE_SQUARE_Y = 140; // Base Y position
176+
int SQUARE_WIDTH = 21; // Width is constant
177+
int MAX_SQUARE_HEIGHT = 35; // Maximum height for 100% charge
178+
// Map battery percentage to square height
179+
int height = map(data, 0, 100, 0, MAX_SQUARE_HEIGHT);
180+
// Choose color based on battery percentage
181+
uint16_t color;
182+
if (data >= 70) {
183+
color = 4;
184+
} else if (data >= 40) {
185+
color = 5;
186+
} else {
187+
color = 3;
188+
}
189+
// Calculate Y position based on height to draw from bottom up
190+
int yPos = BASE_SQUARE_Y + (MAX_SQUARE_HEIGHT - height);
191+
// Draw the battery square
192+
display.fillRect(BASE_SQUARE_X, yPos, SQUARE_WIDTH, height, color);
193+
}

PicoW_DVI_AIO_Display/config.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/************************ Adafruit IO Config *******************************/
6+
7+
// visit io.adafruit.com if you need to create an account,
8+
// or if you need your Adafruit IO key.
9+
#define IO_USERNAME "YOUR-AIO-USERNAME"
10+
#define IO_KEY "YOUR-AIO-KEY"
11+
12+
/******************************* WIFI **************************************/
13+
14+
// the AdafruitIO_WiFi client will work with the following boards:
15+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
16+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
17+
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
18+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
19+
// - Feather WICED -> https://www.adafruit.com/products/3056
20+
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
21+
// - Adafruit Metro M4 Express AirLift Lite ->
22+
// https://www.adafruit.com/product/4000
23+
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
24+
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
25+
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
26+
27+
#define WIFI_SSID "YOUR-WIFI-SSID"
28+
#define WIFI_PASS "YOUR-WIFI-SSID-PASSWORD"
29+
30+
// uncomment the following line if you are using airlift
31+
// #define USE_AIRLIFT
32+
33+
// uncomment the following line if you are using winc1500
34+
// #define USE_WINC1500
35+
36+
// uncomment the following line if you are using mrk1010 or nano 33 iot
37+
//#define ARDUINO_SAMD_MKR1010
38+
39+
// comment out the following lines if you are using fona or ethernet
40+
#include "AdafruitIO_WiFi.h"
41+
42+
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
43+
defined(ADAFRUIT_PYPORTAL)
44+
// Configure the pins used for the ESP32 connection
45+
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
46+
// Don't change the names of these #define's! they match the variant ones
47+
#define SPIWIFI SPI
48+
#define SPIWIFI_SS 10 // Chip select pin
49+
#define NINA_ACK 9 // a.k.a BUSY or READY pin
50+
#define NINA_RESETN 6 // Reset pin
51+
#define NINA_GPIO0 -1 // Not connected
52+
#endif
53+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
54+
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
55+
#else
56+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
57+
#endif
58+
/******************************* FONA **************************************/
59+
60+
// the AdafruitIO_FONA client will work with the following boards:
61+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
62+
63+
// uncomment the following two lines for 32u4 FONA,
64+
// and comment out the AdafruitIO_WiFi client in the WIFI section
65+
// #include "AdafruitIO_FONA.h"
66+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
67+
68+
/**************************** ETHERNET ************************************/
69+
70+
// the AdafruitIO_Ethernet client will work with the following boards:
71+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
72+
73+
// uncomment the following two lines for ethernet,
74+
// and comment out the AdafruitIO_WiFi client in the WIFI section
75+
// #include "AdafruitIO_Ethernet.h"
76+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

PicoW_DVI_AIO_Display/sprites.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#define airWidth 31
6+
#define airHeight 38
7+
const uint8_t PROGMEM airBitmap[] = {
8+
0x00, 0x00, 0x01, 0x80, 0x00, 0x38, 0x03, 0xC0, 0x00, 0x10, 0x07, 0xC0, 0x07,
9+
0x00, 0xC7, 0xC0, 0x0F, 0x81, 0xE3, 0xC0, 0x0F, 0x81, 0xE0, 0x00, 0x0F, 0x81,
10+
0xE0, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x0F,
11+
0x00, 0x00, 0x1E, 0x1F, 0x80, 0x00, 0x3E, 0x3F, 0xC0, 0x00, 0x1E, 0x3F, 0xC0,
12+
0x00, 0x1C, 0x3F, 0xC0, 0x18, 0x00, 0x3F, 0xC0, 0x38, 0x00, 0x1F, 0xC0, 0x10,
13+
0x00, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3F,
14+
0xE0, 0x38, 0x00, 0xFF, 0xF8, 0x38, 0x01, 0xFF, 0xFC, 0x00, 0x03, 0xFF, 0xFC,
15+
0x00, 0x03, 0xFF, 0xFE, 0x00, 0x03, 0xFF, 0xFF, 0x80, 0x07, 0xFF, 0xFF, 0xE0,
16+
0x1F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFC, 0x7F,
17+
0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
18+
0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF,
19+
0xF8, 0x1F, 0xFF, 0xFF, 0xF0, 0x07, 0xFF, 0xFF, 0xC0
20+
};
21+
22+
#define batWidth 29
23+
#define batHeight 46
24+
const uint8_t PROGMEM batBitmap[] = {
25+
0x00, 0xFF, 0xF8, 0x00, 0x01, 0xFF, 0xFC, 0x00, 0x01, 0xFF, 0xFC, 0x00, 0x01,
26+
0xFF, 0xFC, 0x00, 0x01, 0xFF, 0xFC, 0x00, 0x0F, 0xFF, 0xFF, 0x80, 0x3F, 0xFF,
27+
0xFF, 0xE0, 0x7F, 0xFF, 0xFF, 0xF0, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00,
28+
0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70,
29+
0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70,
30+
0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00,
31+
0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00,
32+
0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70,
33+
0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70,
34+
0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00,
35+
0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00,
36+
0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70,
37+
0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70, 0x00, 0x00, 0x70, 0x70,
38+
0x00, 0x00, 0x70, 0x7F, 0xFF, 0xFF, 0xF0, 0x3F, 0xFF, 0xFF, 0xE0, 0x1F, 0xFF,
39+
0xFF, 0xC0
40+
};
41+
42+
#define tempWidth 29
43+
#define tempHeight 47
44+
const uint8_t PROGMEM tempBitmap[] = {
45+
0x00, 0x0F, 0x80, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0xFF, 0xF8, 0x00, 0x01,
46+
0xFF, 0xFC, 0x00, 0x03, 0xFF, 0xFE, 0x00, 0x03, 0xFF, 0xFE, 0x00, 0x07, 0xFF,
47+
0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF,
48+
0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00,
49+
0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07,
50+
0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF,
51+
0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF,
52+
0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x07, 0xFF, 0xFF, 0x00,
53+
0x0F, 0xFF, 0xFF, 0x80, 0x1F, 0xFF, 0xFF, 0xC0, 0x3F, 0xFF, 0xFF, 0xE0, 0x3F,
54+
0xFF, 0xFF, 0xE0, 0x7F, 0xFF, 0xFF, 0xF0, 0x7F, 0xFF, 0xFF, 0xF0, 0x7F, 0xFF,
55+
0xFF, 0xF0, 0xFF, 0xFF, 0xFF, 0xF8, 0xFF, 0xFF, 0xFF, 0xF8, 0xFF, 0xFF, 0xFF,
56+
0xF8, 0x7F, 0xFF, 0xFF, 0xF0, 0x7F, 0xFF, 0xFF, 0xF0, 0x7F, 0xFF, 0xFF, 0xF0,
57+
0x3F, 0xFF, 0xFF, 0xE0, 0x3F, 0xFF, 0xFF, 0xE0, 0x1F, 0xFF, 0xFF, 0xC0, 0x0F,
58+
0xFF, 0xFF, 0x80, 0x07, 0xFF, 0xFF, 0x00, 0x01, 0xFF, 0xFC, 0x00, 0x00, 0x7F,
59+
0xF0, 0x00, 0x00, 0x00, 0x00, 0x00
60+
};
61+
62+
#define waterWidth 31
63+
#define waterHeight 49
64+
const uint8_t PROGMEM waterBitmap[] = {
65+
0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x0F, 0xC0, 0x00, 0x00,
66+
0x0F, 0xE0, 0x00, 0x00, 0x1F, 0xE0, 0x00, 0x00, 0x1F, 0xF0, 0x00, 0x00, 0x3F,
67+
0xF0, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x00, 0x7F, 0xF8, 0x00, 0x00, 0x7F, 0xFC,
68+
0x00, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0xFF, 0xFE, 0x00,
69+
0x01, 0xFF, 0xFE, 0x00, 0x01, 0xFF, 0xFF, 0x00, 0x03, 0xFF, 0xFF, 0x00, 0x03,
70+
0xFF, 0xFF, 0x80, 0x07, 0xFF, 0xFF, 0x80, 0x07, 0xFF, 0xFF, 0xC0, 0x0F, 0xFF,
71+
0xFF, 0xC0, 0x0F, 0xFF, 0xFF, 0xE0, 0x1F, 0xFF, 0xFF, 0xE0, 0x1F, 0xFF, 0xFF,
72+
0xF0, 0x3F, 0xFF, 0xFF, 0xF0, 0x3F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xF8,
73+
0x7F, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFC, 0xFF,
74+
0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
75+
0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF,
76+
0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFC,
77+
0x7F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xF8, 0x1F,
78+
0xFF, 0xFF, 0xF0, 0x0F, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xC0, 0x03, 0xFF,
79+
0xFF, 0x80, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x00, 0x07, 0xC0,
80+
0x00
81+
};

USB_Host_to_BLE_Arduino/.feather_esp32s3_tft.test.only

Whitespace-only changes.

0 commit comments

Comments
 (0)