* Debounce ESP32 https://www.switchdoc.com/2018/04/esp32-tutorial-debouncing-a-button-press-using-interrupts/ * parts Digikey MAX488ECPA+-ND Tranceiver 3.98 Digikey S7002-ND 4x1 Female Header 0.45 Digikey S7108-ND 5x2 Female Header 0.71 Digikey S7074-ND 6x2 Female Header 0.79 Digikey 102-6181-ND 4 position terminal 0.97 Digikey 102-6204-ND 3 position terminal 0.79 Digikey 10118193-0001LF micro usb connector 0.48 M2018TXW13-GA-ND --> NKK black paddle switch : $5.80 360-2588-ND --> NKK red push button switch : $4.785 360-2726-ND --> NKK black push button switch : $4.738 * Install u8g2 (OLED display) library for arduino-cli arduino-cli lib -help arduino-cli lib update-index arduino-cli lib list arduino-cli lib search U8g2 arduino-cli lib install 'U8g2' arduino-cli board list arduino-cli compile --fqbn esp32:esp32:esp32wrover jackESP32 arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32wrover jackESP32 * Minicom Notes (exit minicom while flashing) minicom -s -D /dev/ttyUSB0 ctrl-a z o 9600 hardware flow control : no esc esc ctrl-a z o e - local echo * 1106 FullFrame U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); void setup(void) { u8g2.begin(); } void loop(void) { // picture loop u8g2.clearBuffer(); draw(); u8g2.sendBuffer(); delay(100); } * ************************************************************************************* * ESP32 Pinout * ************************************************************************************* * Note : GPIO 34-39 are input only, and do not have pullups these would be good for ADC inputs GPIO 15 -> SPI CS GPIO 14 -> SPI CLK GPIO 13 -> SPI MOSI GPIO 12 -> SPI MISO (Must not pull high during flash) GPIO 21 -> SDA GPIO 22 -> SCL GPIO 0 --> Output GPIO 2 --> Output GPIO 4 --> Output GPIO 32 --> Output GPIO 33 --> Output * -------------------------------------------------- * T38 --> GND - connect to gnd plane T37 --> GPIO 23 - *** Use Me *** T36 --> GPIO 22 - *** SCL T35 --> TXD0 - *** TX T34 --> RXD0 - *** RX T33 --> GPIO 21 - *** SDA T32 --> GND - connect to gnd plane T31 --> GPIO 19 - *** Use Me *** T30 --> GPIO 18 - *** Use Me *** T29 --> GPIO 5 - *** Use Me *** T28 --> GPIO 17 - *** TX2 *** T27 --> GPIO 16 - *** RX2 *** T26 --> GPIO 4 - *** LED4 Output *** T25 --> GPIO 0 - *** LED0 Output *** T24 --> GPIO 2 - *** LED2 Output *** T23 --> GPIO 15 - *** SPI Header CS *** T22 --> SD1 - Float T21 --> SD0 - Float T20 --> CLK - Float * * B01 --> 3V3 - *** 3.3 to Header Pins and Open DIP and Pullups *** B02 --> EN B03 --> VP - *** Figure Out *** B04 --> VN - *** Figure Out *** B05 --> GPIO 34 - *** Assign Me *** B06 --> GPIO 35 - *** Assign Me *** B07 --> GPIO 32 - *** LED32 Output *** B08 --> GPIO 33 - *** LED33 Output *** B09 --> GPIO 25 - *** DAC1 *** B10 --> GPIO 26 - *** DAC2 *** B11 --> GPIO 27 - *** PWM *** B12 --> GPIO 14 - SPI Header CLK B13 --> GPIO 12 - SPI Header MISO B14 --> GND - connect to gnd plane B15 --> GPIO 13 - SPI Header MOSI B16 --> SD2 - Float B17 --> SD3 - Float B18 --> CMD - Float B19 --> 5V - jumper select bottom USB or ECC * * * ************************************************************************************* * HiLetgo 1.3" I2C 128x64 SSH1106 OLED On 8266 SCL = D1 SDA = D2 use U8g2 library (which is the update to U8glib) Works fine on both Arduino and ESP8266 It has a graphics mode and an 8x8 text mode The 8x8 text mode needs less memory, and can do some nice large fonts The graphics mode is more powerful however You must uncomment out the constructor for this display : U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); #include void setup(void) { u8g2.begin(); u8g2.firstPage(); do { u8g2.setFont(u8g2_font_6x10_tf); u8g2.setFontRefHeightExtendedText(); u8g2.setDrawColor(1); u8g2.setFontPosTop(); u8g2.setFontDirection(0); u8g2.drawStr(5, 10, "Hello World"); u8g2.drawLine(5, 10, 50, 60); } while( u8g2.nextPage() ); delay(1000); } void loop(void) { static int jval = 0; u8g2.firstPage(); do { u8g2.setFont(u8g2_font_6x10_tf); u8g2.setFontRefHeightExtendedText(); u8g2.setDrawColor(1); u8g2.setFontPosTop(); u8g2.setFontDirection(0); u8g2.drawStr(5 + jval * 2, 10 + jval, "Hello World"); u8g2.drawLine(5, 10, 50, 60); } while( u8g2.nextPage() ); jval = jval + 1; if (jval > 10) { jval = 0; } delay(1000); } You can base your code on the examples from the U8g2 library under the "page_buffer" tab In these examples, you need to delete the stuff in setup where he configures some pins as outputs. I'm not sure what this is for, but it causes these demo programs to not run on an ESP8266 * ************************************************************************************* * ESP32 WROVER 1E - DMA SPI * ************************************************************************************* I just notice if pin 12 is pulled high on my board I cannot flash (I get an MD5 error) I can force pin 12 low, or I can let it float, but I cannot let it be high * ************************************************************************************* * ************************************************************************************* * ESP32 WROVER 1E * ************************************************************************************* vim ~/.arduino15/arduino-cli.yaml board_manager: additional_urls: [https://dl.espressif.com/dl/package_esp32_index.json, https://arduino.esp8266.com/stable/package_esp8266com_index.json] arduino-cli board update-index arduino-cli core update-index arduino-cli core search esp32 arduino-cli core install esp32:esp32 arduino-cli board list arduino-cli board listall arduino-cli compile --fqbn esp32:esp32:esp32wrover MyFirstSketch sudo yum list | grep pip sudo yum install python2-pip.noarch sudo pip install serial sudo pip install pyserial arduino-cli compile --fqbn esp32:esp32:esp32wrover MyFirstSketch arduino-cli compile --fqbn esp32:esp32:esp32wrover my32 arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32wrover my32 * ************************************************************************************* * Example : Run this on python3 in PowerShell * ************************************************************************************* https://docs.microsoft.com/en-us/windows/python/beginners https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers Get the CP210x Universal Windows Driver v11.1.0 (3/21/2022) zip file Extract it plug your USB Uart board in Control_Panel --> Devices_and_Printers Right_Click on the new device that shows up, then click properties Then click hardware tab, then click properties, then click change_settings Then click driver tab, intsall or update driver, then browse to the folder you extracted above Open a powershell as admin type python3 --> brings up micorsoft store python 3.10 Install it Now open a new powershell as admin pip3 install serial pip3 install pyserial Now open a new powershell as admin cd \Users\warwargr\DD python3 import serial ser = serial.Serial(port="COM4", baudrate=9600) ser ser.write(b'Hello World') ser.timeout=0 sbuf = ser.read(100) sbuf sbuf = ser.read(100) sbuf exit * ************************************************************************************* * Example : * ************************************************************************************* greg ~$ python3 >>> import serial >>> ser = serial.Serial('/dev/ttyS9', 9600) >>> ser Serial(port='/dev/ttyS9', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False) >>> ser.timeout=0 >>> ser.write(b'Hello World\n') 12 >>> sbuf = ser.read(100) >>> sbuf b'REC : Hello World\r\n' >>> quit() * ************************************************************************************* * WSL serial port https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers sudo pip3 install serial sudo pip3 install pyserial sudo usermod -aG dialout greg (open new Debian Window) (plug in FT232 - verify it's recognized as COM8) (COM8 --> /dev/ttyS8) groups greg (verify member of dialout) python3 import serial ser = serial.Serial('/dev/ttyS8', 9600) ser.write(b'Hello World') * Add esp8266 url (This is the file : /home/greg/.arduino15/arduino-cli.yaml) (recreate with : arduino-cli config init --overwrite) board_manager: additional_urls: [https://arduino.esp8266.com/stable/package_esp8266com_index.json] daemon: port: "50051" directories: data: /home/greg/.arduino15 downloads: /home/greg/.arduino15/staging user: /home/greg/Arduino library: enable_unsafe_install: false logging: file: "" format: text level: info metrics: addr: :9090 enabled: true sketch: always_export_binaries: false 1099 vim /home/greg/.arduino15/arduino-cli.yaml 1098 arduino-cli core update-index 1111 arduino-cli core search esp8266 1112 arduino-cli core install esp8266:esp8266 1113 arduino-cli board list 1114 arduino-cli board listall 1116 arduino-cli compile --fqbn esp8266:esp8266:nodemcu ESP8266_SSD1306_HelloSerial 1120 arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcu ESP8266_SSD1306_HelloSerial * arduino-cli curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh arduino-cli -h 1003 mkdir afirst 1004 cd afirst 1005 arduino-cli config init 1006 arduino-cli sketch new MyFirstSketch 1008 cd MyFirstSketch/ 1010 vim MyFirstSketch.ino 1012 cd .. 1013 arduino-cli core update-index 1014 arduino-cli board list 1015 arduino-cli board listall mkr 1016 arduino-cli board listall avr 1017 arduino-cli board listall uno 1018 arduino-cli board listall 1019 arduino-cli core install arduino:avr 1020 arduino-cli core list 1021 arduino-cli board listall 1022 arduino-cli board list 1024 arduino-cli compile --fqbn arduino:avr:uno MyFirstSketch 1026 lls /dev/tty* 1027 arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno MyFirstSketch ****************************************** * Install Adafruit SSD1306 library ****************************************** 1009 arduino-cli compile -p /dev/ttyACM0 --fqbn arduino:avr:uno GregUnoDisplay 1010 arduino-cli -help 1011 arduino-cli lib -help 1012 arduino-cli lib update-index 1014 arduino-cli lib list 1015 arduino-cli lib examples 1016 arduino-cli lib search 1024 arduino-cli lib search Adafruit | grep -i SSD1306 | grep -i name 1025 arduino-cli lib search Adafruit > junk.jnk 1026 vim junk.jnk 1029 arduino-cli lib install 'Adafruit SSD1306' * Deconvolving Arduino Process Here it is!!!!!! https://arduino.github.io/arduino-cli/latest/getting-started/ follow this and all things become clear please try this on the student VM Run thru the demo, and then simply go to /tmp and you'll find everything The real gold is the file : compile_commands.json This is better than a make file. It has everything! https://arduino.github.io/arduino-cli/sketch-build-process/ https://arduino.github.io/arduino-cli/platform-specification/ https://arduino.github.io/arduino-cli/latest/installation/ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=~/local/bin sh * SAM D21 SPI https://microchipdeveloper.com/32arm:samd21-sercom-spi-master-configuration https://github.com/ostaquet/Arduino-Nano-33-IoT-Ultimate-Guide https://microchipdeveloper.com/32arm:samd21-code-gcc-sercom-spi-master-example https://microchipdeveloper.com/local--files/32arm:samd21-code-gcc-sercom-spi-master-example/32arm-samd21-gcc-sercom-spi-master-demo.zip https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi * SPI Master Mode // SCK = PINB5 = Digital 13 (Output) // MISO = PINB4 = Digital 12 (Input) // MOSI = PINB3 = Digital 11 (Output) // CS = PINB2 = Digital 10 (Output) #define SPI_DDR DDRB #define CS PINB2 #define MOSI PINB3 #define MISO PINB4 #define SCK PINB5 void SPI_init() { // set CS, MOSI and SCK to output SPI_DDR |= (1 << CS) | (1 << MOSI) | (1 << SCK); // enable SPI, set as master, set SPI_Mode=3, and clock to fosc/128 SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPOL) | (1 << CPHA) | (1 << SPR1) | (1 << SPR0); } uint8_t SPI_send(uint8_t data) { // load data into register SPDR = data; // Wait for transmission complete while(!(SPSR & (1 << SPIF))); // return Data Register return SPDR; } * Arduino Reference https://gammon.com.au/forum/bbshowpost.php?bbtopic_id=123 https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/ * *********************************************************************************************** * Serial Ports - NodeCMU ESP12F 8266 * *********************************************************************************************** https://github.com/esp8266/Arduino/blob/master/doc/reference.rst#serial The serial ports are very easy to use Serial.begin(9600); Serial.swap(); Normally the serial port is GPIO1 - TX GPIO3 - RX The Serial.swap() function moves it to GPIO15 - D8 - TX GPIO13 - D7 - RX The problem with using GPIO3 as RX is that you have to disconnect it during flashing. This is like the Arduino. Note that when you swap it however, you can no longer use the Arduino IDE serial port monitor. When you do use the serial port monitor, not that the TX signal goes both to the pin and the serial port monitor. The RX signal could come from either the monitor (USB) or the RX pin. I believe the monitor is higher impedance, to the RX pin dominates if connected, but in any case this is probably another reason to switch to the GPIO13 (D7) as the RX pin with the Serial.swap() To read the serial port while (Serial.available() > 0) { ch = Serial.read(); . . . } To print, use Serial.println("Hello World") * *********************************************************************************************** * Simple Example Program for ESP8266 // * *************************************************************************** #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); Serial.println("Enter display.begin"); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); Serial.println("Leave display.begin"); display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.println("Hello World!"); display.println(""); display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); display.println("3.141592"); display.println(""); display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.print("Hello "); display.println("Jack"); display.display(); delay(2000); display.clearDisplay(); display.drawRect(0, 0, display.width(), display.height(), SSD1306_WHITE); display.display(); } void loop() { static int ival = 0; char jstr[32]; display.setTextColor(SSD1306_WHITE, SSD1306_BLACK); display.setCursor(5,12); sprintf(jstr, "I = %3d", ival); display.println(jstr); display.setCursor(5,36); sprintf(jstr, "J = %3d", ival*3); display.println(jstr); display.display(); ival = ival + 1; if (ival >= 100) { ival = 0; } delay(1000); } // * *************************************************************************** * Maker Focus SSD1306 Displays I bought four of these from Amazon They are 128x64 There is some confusion as to the I2C address. As pointed out in an Amazon Review, on the board itself it lists 0x78 but the correct address is 0x3C. You can install the Adafruit SSD1306 Library and Adafruit GFX Libraries from the Arduino IDE library manager For some reason, the I2C addresses in the examples show 0x3C for a 128x32 display, and 0x3D for a 128x64 display These are 128x64 displays, but the correct address is 0x3C. I found this by trial and error, but then found that the Amazon reviewer noted that 0x3C is correct too. On the Arduino Uno, you connect the SDA-->A4, SCL-->A5 On the ESP8266, you connect the SDA-->GPIO4=D2, SCL-->GPIO5=D1 It is very important to set : OLED_RESET = -1 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C) To get started, you can load up the ssd1306_128x64_i2c example sketch Change I2C address 0x3D to 0x3C Change OLED_RESET from 4 to -1 * Wifi with screen https://www.youtube.com/watch?v=QVOMVSsF1aE * You really need to download the arduino ide all the code for libraries is in : /cygdrive/c/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor cd /cygdrive/c/Program\ Files\ \(x86\)/Arduino/hardware/arduino/ * *************************************************** sudo yum install avr-gcc.x86_64 avrdude.x86_64 sudo yum install avr-libc.noarch ll /dev/tty* > junk1.txt (plug in arduino) ll /dev/tty* > junk2.txt diff junk1.txt junk2.txt vim MakeFile good totorial ( https://bytes.usc.edu/files/ee109/labs/lab1v/EE109Lab1.pdf ) * **************************************** DEVICE = atmega328p CLOCK = 16000000 PROGRAMMER = -c arduino -b 115200 -P /dev/ttyACM0 OBJECTS = gregArdo.o lcdFast.o FUSES = -U hfuse:w:0xde:m -U lfuse:w:0xff:m -U efuse:w:0x05:m # Tune the lines below only if you know what you are doing: AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)