ODROID ODROID-GO Manuale utente

2023/05/05 21:45 1/5 Arduino for ODROID-GO - Blue LED and PWM
ODROID Wiki - https://wiki.odroid.com/
Arduino for ODROID-GO - Blue LED and PWM
Make sure that you've followed these guides.
Getting started with Arduino
Arduino for ODROID-GO - Hello World
Refer to the Arduino official documents. This tells us useful common functions
with great instructions.
https://www.arduino.cc/reference/en/
Refer to the ESP32 official programming guide. Most of ESP32 specific functions
introduced here.
https://esp-idf.readthedocs.io/en/v3.0/
We don't need odroid_go.h library for this step.
You can implement the breathing effect as well by using fading functions in the
ledc.h. Not to be dealt with in this guide.
We will learn that how to control the blue status LED on the board and how to adjust PWM value to
give a breathing effect to the LED with Arduino.
Blink the blue LED

Last update:
2018/06/11
12:25
odroid_go:arduino:03_blue_led_and_pwm https://wiki.odroid.com/odroid_go/arduino/03_blue_led_and_pwm?rev=1528687521
https://wiki.odroid.com/ Printed on 2023/05/05 21:45
Let's make the LED blinks permanently.
Open a new sketch by pressing the shortcut CTRL-N.
You're able to control that LED very easily.
The pin number for the LED is 2. Define that with Preprocessor.
First, we have to make the pin as output mode, use pinMode() function to do that.
#define PIN_BLUE_LED 2
void setup() {
// put your setup code here, to run once:
pinMode(PIN_BLUE_LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
}
Now the pin is in ready.
You can write a signal in bits by using digitalWrite() function. Surely this function have to be in
loop() function to run repeatedly.
And give a delay() function to slow down the blink.
#define PIN_BLUE_LED 2
void setup() {
// put your setup code here, to run once:
pinMode(PIN_BLUE_LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(PIN_BLUE_LED, HIGH);
delay(500);
digitalWrite(PIN_BLUE_LED, LOW);
delay(500);
}
Press CTRL-U to compile and upload the sketch.
Then you can see the blue LED blinks.

2023/05/05 21:45 3/5 Arduino for ODROID-GO - Blue LED and PWM
ODROID Wiki - https://wiki.odroid.com/
Give the LED to breathing effect
With adjusting analog output value, as known as PWM, we can make the LED breathing.
Arduino gives us wrappers that helps control of GPIO pins, as well as to control of PWM features.
Generally these PWM functions calls analogRead() and analogWrite(), but it's not yet available in
ESP32 so that we should use ledcRead() and ledcWrite() functions to control the LEDs since the
way to control PWM values in ESP32 is differed from in the others.
These functions are made for using LED PWM features for ESP32, and belongs to ledc.h (LED
Control).
In ESP32, the LED PWM is composed of 16 independent channels, and we can configure duty cycles
with its resolution and wave periods by accessing these channels.
So let's get it started.
First of all, we should choose a channel to attach from the LED to. It is available 0 to 7, we will use
channel 1.
Define it through a Preprocessor, and the blue LED too.
#define PIN_BLUE_LED 2
#define PWM_CHANNEL 1
void setup() {
// put your setup code here, to run once:
}

Last update:
2018/06/11
12:25
odroid_go:arduino:03_blue_led_and_pwm https://wiki.odroid.com/odroid_go/arduino/03_blue_led_and_pwm?rev=1528687521
https://wiki.odroid.com/ Printed on 2023/05/05 21:45
void loop() {
// put your main code here, to run repeatedly:
}
And control the pin mode of the LED to output. It might be not a necessary step, but to make sure.
#define PIN_BLUE_LED 2
#define PWM_CHANNEL 1
void setup() {
// put your setup code here, to run once:
pinMode(PIN_BLUE_LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
}
Attach the LED pin to the channel we defined.
Next, setup that channel runs in 12kHz, 8 bit resolution.
#define PIN_BLUE_LED 2
#define PWM_CHANNEL 1
void setup() {
// put your setup code here, to run once:
pinMode(PIN_BLUE_LED, OUTPUT);
ledcAttachPin(PIN_BLUE_LED, PWM_CHANNEL);
ledcSetup(PWM_CHANNEL, 12000, 8);
}
void loop() {
// put your main code here, to run repeatedly:
}
Lastly, add a breathing code into the loop() function.
We defined a variable calls pinVal as a global variable to prevent from allocating a new memory
repeatedly in the loop() function.
#define PIN_BLUE_LED 2
#define PWM_CHANNEL 1
int pinVal = 0;
void setup() {
// put your setup code here, to run once:
pinMode(PIN_BLUE_LED, OUTPUT);

2023/05/05 21:45 5/5 Arduino for ODROID-GO - Blue LED and PWM
ODROID Wiki - https://wiki.odroid.com/
ledcAttachPin(PIN_BLUE_LED, PWM_CHANNEL);
ledcSetup(PWM_CHANNEL, 12000, 8);
}
void loop() {
// put your main code here, to run repeatedly:
for (; pinVal >= 0; pinVal--) {
ledcWrite(PIN_CHANNEL, pinVal);
delay(3);
}
for (; pinVal < 256; pinVal++) {
ledcWrite(PIN_CHANNEL, pinVal);
delay(3);
}
}
Press CTRL-U to compile and upload the sketch.
Then you can see the blue LED breathing.
From:
https://wiki.odroid.com/ - ODROID Wiki
Permanent link:
https://wiki.odroid.com/odroid_go/arduino/03_blue_led_and_pwm?rev=1528687521
Last update: 2018/06/11 12:25
Indice

















