You are on page 1of 19

Christmas Homework

Smile! It’s fun!


Remember
1. Select the right board, COM port
2. Set the Serial.begin speed to 115200 in the setup() function (or
change the speed in the serial monitor)
3. Do your sensor connections when your arduino is disconnected
4. If you board is non responding to the upload, check the COM port
(should be branded Silicon Labs), and also try without any wire
connected.
Before you begin
Before you begin
Fixing the missing libraries in the examples
• There is a bug in the Arduino extension for VS-Code. The editor does
no reference the libraries we installed. Therefore, the added libraries
in the examples are not found: eg.

• I created a pull request but until it’s accepted and an update is


available, you can replace the file with the fixed version:
• Copy the attached file to this folder and replace the existing file:
\VSCode\data\extensions\vsciot-vscode.vscode-arduino-0.2.28\out\src\arduino
More info on the missing libs
• Although vscodePaths to libraries are set in each project in the
.vscode/c_cpp_properties.json file.
• Your file should resemble like this:
Too much debug when uploading…
The status bar

Open
Program serial
Board
to run monitor

Select
serial
port

Bonus: Auto-scroll:
First, let’s revise the basics
1. Open the Blink example and play with the delay
2. Using the copy/move lines (Alt+Up/down | Alt+Shift+Up/down)
duplicate the correct lines to make an SOS in Morse: ... - - - …
3. A bit of coding: Use the for loop to simplify your SOS
1. Just type for and select the for snippet code
2. Use TAB to get to each part of the snippet

for (size_t i = 0; i < 3; i++)


{
Serial.println("Print this 3 times");
}
BONUS: change the LED_BUILTIN pin and plug in your Relay or a LED
Note: esp32 ttgo doesn’t have a LED_BUILTIN, so… use a relay or a LED
Connecting a relay module
Warning: do not touch any wires that are connected to mains voltage. Also make sure you
have tighten all screws of the relay module.

• IN1 connected to eg GPIO12. When digitalWrite(12,HIGH) the lamp


will turn ON.
https://randomnerdtutorials.com/guide-for-relay-module-with-arduino/
Going further
• Esp32 ttgo has no led builtin, so you need a led… or your relay.
• Link the blink delay with the value of an analog input (esp8266: A0,
esp32: any of the green pins in slide 4, eg analogRead(2):
• Use Serial.begin and Serial.println to print on the serial port when the
led is on or off.
Sensors: DS18B20
• 2 libraries needed:
Remember to add a resistor!
(not needed on ESP8266 port 2/D4)

• Example: Custom libraries\Dallas Temperature\Simple


1. Rename Simple.pde to Simple.ino (F2 on the filename)
2. Set the right PIN line 6.
3. Set Serial.begin speed to 115200
4. Put the value of the sensor in a variable of type float
5. Test the variable, if it’s >28 turn a pin HIGH, and print a line on the serial
6. Plug a relay or a led to test
Tutorial for esp8266 + web interface Tutorial for esp32 + web interface
https://randomnerdtutorials.com/esp8266-ds18b20- https://randomnerdtutorials.com/esp32-ds18b20-
temperature-sensor-web-server-with-arduino-ide/ temperature-arduino-ide/
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
if (temp>27)
{
digitalWrite(LED_BUILTIN,HIGH);
Serial.println("Temperature is higher than 27!!");
}
else
{
digitalWrite(LED_BUILTIN,LOW);
/* code */
}
Sensors: BPM180
• 1 library needed:

• Example: BMP085
1. Get example BMP085test and upload it
2. Connect 3.3v, GND, scl/sda ports (esp32: 22/21; esp8266: D1/D2)
3. Put the value of the sensor in a variable of type float
4. Test the variable if it >28 turn a pin HIGH, and print a line on the serial
5. Plug a relay or a led to test

https://randomnerdtutorials.com/esp32-with-bmp180-
barometric-sensor/
Esp32 ttgo: turn ON the screen!
• Library:

• Open

Comment //

Uncomment

https://github.com/Xinyuan-LilyGO/TTGO-T-Display
#define TFT_WIDTH 135
More info on the library: https://github.com/Bodmer/TFT_eSPI #define TFT_HEIGHT 240
Esp32 ttgo: turn ON the screen!
• Now you can run the examples of the tft_espi library
• Simple example: Colour_test

• Funnier:
• 160 x 128\Pong_v3 (adjust screen size)
• Usefull: tft_meter5
Exercise
• From the sensor example, add the needed functions and library to
print the temperature on the screen
Help!
• Frequent errors:
• Wrong COM port selected Wrong COM port selected

• Wrong BOARD selected


Merry Christmarduino!

You might also like