Build EmbeddedwithAI Intelligence
AI Intelligence
UnityMbed powered by AI. The ultimate ecosystem from coding to board flashing. Develop Embedded Systems smarter and faster than ever.
Write, build and flash in one session
A real N32G031 session: GPIOA clocks, DHT11 on the wire, click-to-flash.
UM
N32G031_OLED_DHT11-mainn32g031 saved to diskN32G031_OLED_DHT11-main
>Linked to disk · ~/Projects/N32G031_OLED_DHT11
flash ok · 240 bytes · 0.8s · OpenOCD n32g031Files
Files
src
7misc.c
n32g031_it.c
oled.c
system_n32g031.c
utils.c
drivers
51filemain
2inc
10Tools
Hardware
2Toolchain
1Cloud
3Account
4Advanced
2⌘Kquick search
main.c✕
src/main.c
AI on
1#include "n32g031.h"
2#include "n32g031_gpio.h"
3#include "n32g031_rcc.h"
4#include "core_cm0.h"
5#include "dht11.h"
6#include "oled.h"
7#include "utils.h"
8#include <stdio.h>
9
10// --- ADDED: LED Initialization ---
11void leds_init(void)
12{
13 // Enable GPIOA clock (Bit 2 in APB2PCLKEN)
14 RCC->APB2PCLKEN |= (1U << 2);
15
16 // Configure PA2 (Yellow), PA3 (Green), PA4 (Red) as Output (01)
17 GPIOA->PMODE &= ~((3U << 4) | (3U << 6) | (3U << 8));
18 GPIOA->PMODE |= ((1U << 4) | (1U << 6) | (1U << 8));
19
20 // Configure as Push-Pull (0)
21 GPIOA->POTYPE &= ~((1U << 2) | (1U << 3) | (1U << 4));
22
23 // Configure No Pull-up/Pull-down (00)
24 GPIOA->PUPD &= ~((3U << 4) | (3U << 6) | (3U << 8));
25
26 // Turn all LEDs OFF initially (write 1 to Port Bit Clear register)
27 GPIOA->PBC = (1U << 2) | (1U << 3) | (1U << 4);
28}
29// ---------------------------------
30
31int main(void)
32{
33 uint8_t current_temp = 0;
34 uint8_t current_humi = 0;
35
36 uint8_t last_temp = 255;
37 uint8_t last_humi = 255;
38 uint8_t was_error = 1;
39
40 uint8_t error_count = 0;
41
42 char buffer[20];
43
44 SystemInit();
45 SystemCoreClockUpdate();
46
47 leds_init(); // Initialize the 3 LEDs
48
49 delay_ms(500);
50 OLED_Init();
51 OLED_Clear();
52 DHT11_Init();
53
54 OLED_ShowString(10, 24, "System Ready", 16);
55 delay_ms(1500);
56
57 OLED_Clear();
58
59 while (1)
60 {
61 if (DHT11_Read_Data(¤t_temp, ¤t_humi) == 1)
62 {
63 error_count = 0;
64
65 if (was_error)
66 {
67 OLED_Clear();
68 OLED_ShowString(0, 0, "Temp: ", 8);
69 OLED_ShowString(0, 32, "Humidity: ", 8);
70 was_error = 0;
71 last_temp = 255;
72 last_humi = 255;
73 }
74
75 if (current_temp != last_temp)
76 {
77 sprintf(buffer, "%02d C ", current_temp);
78 OLED_ShowString(0, 12, buffer, 16);
79 OLED_ShowString(24, 12, "o", 8);
80 last_temp = current_temp;
81 }
82
83 if (current_humi != last_humi)
84 {
85 sprintf(buffer, "%02d %% ", current_humi);
86 OLED_ShowString(0, 44, buffer, 16);
87 last_humi = current_humi;
88 }
89
90 // --- ADDED: LED Logic based on Humidity ---
91 if (current_humi < 40)
92 {
93 GPIOA->PBSC = (1U << 3); // Green ON (PA3)
94 GPIOA->PBC = (1U << 2) | (1U << 4); // Yellow, Red OFF
95 }
96 else if (current_humi >= 40 && current_humi <= 60)
97 {
98 GPIOA->PBSC = (1U << 2); // Yellow ON (PA2)
99 GPIOA->PBC = (1U << 3) | (1U << 4); // Green, Red OFF
100 }
101 else
102 {
103 GPIOA->PBSC = (1U << 4); // Red ON (PA4)
104 GPIOA->PBC = (1U << 2) | (1U << 3); // Green, Yellow OFF
105 }
106 // ------------------------------------------
107 }
108 else
109 {
110 error_count++;
111
112 if (error_count >= 3)
113 {
114 if (!was_error)
115 {
116 OLED_Clear();
117 was_error = 1;
118 }
119 OLED_ShowString(0, 0, "Sensor Error! ", 16);
120 OLED_ShowString(0, 24, "Check Wiring. ", 16);
121
122 // Optional: Turn off all LEDs on error
123 GPIOA->PBC = (1U << 2) | (1U << 3) | (1U << 4);
124 }
125 }
126
127 delay_ms(2000);
128 }
129}
AI ASSISTANT
N32G031 connectedPro ctx 0.0k
Flash onto N32G031 kits
Starter, Pro and Learning kits share the same Cortex-M0+ board. Rotate a kit, then order from the form below.
Starter Kit Board
Features a classic Uno-style footprint for maximum compatibility with standard off-the-shelf hardware shields.
Beginner-FriendlyPlug & PlayAll-in-One
Partners
































Choose a plan
Already subscribed?Sign in to manage your plan →
AI models vary by plan; see each plan for the models included
| Compare plans | Free | Starter | Pro Most Popular | Advance | Enterprise |
|---|---|---|---|---|---|
| Price | Free | ฿249/month | ฿550/month | ฿990/month | Custom |
| Seats | 1 User | 1 User | 1 User | 1 User | Seats based on organization structure |
| Credits | 200 Credits | 2,000 Credits | 7,000 Credits | 13,000 Credits | Custom Credits |
| AI Model Access | Fast | Fast | Fast · Balanced · Smart | Fast · Balanced · Smart · Pro | Fast · Balanced · Smart · Pro |
| Flexibility | Basic trial use | General use | Regular use | Advanced use | Customizable for organization needs Premium Support |
Install the desktop IDE
WINDOWS 10/11
Windows
MACOS 12+
Mac OS
ANY DISTRO
Linux
GET IN TOUCH
BUSINESS HOURS
Monday - Friday: 9:00am - 8:00pm
Closed on Weekends & Public Holidays




