/* Specification & Vendor Information: ----------------------------------- OLED - Spec: 2.42 inch 2.42" OLED Display Module 128x64 LCD HD Screen Module SSD1309 7 Pin SPI/IIC I2C Serial Interface for Arduino UNO R3 OLED - Vendor: https://de.aliexpress.com/item/1005006473260235.html Recommended Readings: --------------------- Hardware considerations (MC - Thread): https://www.mikrocontroller.net/topic/566536?goto=7642989#7642989 Burning Bootloaders: https://forum.arduino.cc/t/how-to-burn-boot-loader-of-arduino-uno-r3-usin-aurdino-mega-2650/320626 Library for monochrome displays, v2: https://github.com/olikraus/u8g2 Very good Pinouts for all Arduinos: https://devboards.info/ PWM: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/ Arduino Boards tested: ---------------------- Arduino Uno R3: https://store.arduino.cc/products/arduino-uno-rev3 (Product Page) (not testet yet) https://docs.arduino.cc/hardware/uno-rev3/ (Documentation) Arduino Nano v3: https://store.arduino.cc/products/arduino-nano (Product Page) https://docs.arduino.cc/hardware/nano/ (Documentation) Arduino Mega 2560 Rev3: https://store.arduino.cc/products/arduino-mega-2560-rev3 (Product Page) https://docs.arduino.cc/hardware/mega-2560/ (Documentation) Sparkfun Pro Micro - 5V/16 MHz: https://www.sparkfun.com/products/12640 (Product Page) https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide (Documentation) Arduino Pro Mini (Clone from deep-robot): https://www.pixelelectric.com/development-boards/arduino/boards/arduino-pro-mini-5v-16mhz/ (Product Page) (not tested yet) Datasheets Display and surrounding Hardware: -------------------------------------------- X6206 - Voltage Regulator: https://product.torexsemi.com/system/files/series/xc6206.pdf HM1308 - Step-up DC/DC Converter: https://www.hmsemi.com/index.php/Down/down/id/1519.html SSD1309 - OLED Driver with Controller: https://www.hpinfotech.ro/SSD1309.pdf Pinout & Wiring: ---------------- OLED 2.42ยดยด SPI - SSD1309 UNO R3 Nano Mega 2560 Rev3 Sparkfun Pro Micro ------------------------- ---------- --------- -------------- ------------------ CS (chip select) 10 (SS) 10 53 10 DC (data/commands) 9 9 49 9 RES (reset) 7 7 48 7 SDA (serial data) 11 (MOSI) 11 (MOSI) 51 (COPI) 16 (MOSI) SCLK (clock) 13 (SCK) 13 (SCK) 52 (SCK) 15 (SCLK) VDD (supply voltage) +5 V +5V +5V +5V VSS (GND - ground) GND GND GND GND PeDa-Oscillator --------------- Oscillator-Signal 8 8 ? 8 Vcc +5V +5V +5V +5V GND GND GND GND GND Wiring References: References for Arduino UNO: https://www.robotics.org.za/OLED242W-SPI https://forum.arduino.cc/t/2-42-oled-ssd1309-with-u8glib/425247/3 https://electropeak.com/learn/interfacing-2-42-inch-oled-spi-i2c-display-module-with-arduino/ References for Nano: ... the Nano uses the same wiring as the UNO does - you can refer to the UNO references References for Mega 2560: ... could not find a decent one ... Refs for Sparkfun Pro Micro: General good explanation: https://forum.arduino.cc/t/solved-ssd1309-with-spi-to-arduino-micro-help/1205438/4 Pinout References: Arduino UNO R3: https://docs.arduino.cc/hardware/uno-rev3/ (official site) https://www.circuito.io/blog/arduino-uno-pinout/ Arduino Nano: https://docs.arduino.cc/hardware/nano/ (official site) https://devboards.info/boards/arduino-nano Arduino Mega 2560: https://docs.arduino.cc/hardware/mega-2560/ (official site) https://devboards.info/boards/arduino-mega2560-rev3 Sparkfun Pro Micro: https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro (official site) https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide SPI Pinout: Arduinos - many types: https://www.arduino.cc/reference/en/language/functions/communication/spi/ Arduino-Terminology (old vs. new) Master/Slave (OLD) Controller/Peripheral (NEW) -------------------------- ------------------------------------ Master In Slave Out (MISO) Controller In, Peripheral Out (CIPO) Master Out Slave In (MOSI) Controller Out Peripheral In (COPI) Slave Select pin (SS) Chip Select Pin (CS) Reference: https://docs.arduino.cc/learn/communication/spi/ */ /* The program is using Oliver Kraus' libraries (U8g2) Reference: https://github.com/olikraus/u8g2 */ #include #include #include #include #include #include #include #include // Set pinout int pin = 8; // pin for puls input from oscillator int pout = 3; // pin for PWM output (just a reference-signal for testing) - must be a "pwm-capeable" pin. // Constructor - for OLED display library - see u8g2 documentation U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI u8g2(U8G2_R0, 10, 9, 7); volatile uint16_t pulse_width; volatile bool isFinished; char buffer[32]; uint16_t min; uint16_t max; uint8_t noOfPulses = 80; // number of pulses to use for a measurement. Do not choose // to large values as sum of all pulseLength must fit in a uint16_t variable // i.e.: noOfPulses x pulseLenth < 65536 void setup() { pinMode(pin, INPUT); pinMode(pout, OUTPUT); u8g2.begin(); // start the u8g2 library u8g2.setBitmapMode(1); u8g2.setFont(u8g2_font_helvB08_tr); analogWrite(pout, 6); // just for testing: set up a 50% PWM at pout pin TCCR1A = 0; TCCR1B = (1< max) { max = max + (pulseLength - max) / 2 + 1; } if(pulseLength < min) { min = min - (min - pulseLength) / 2 - 1; } u8g2.clearBuffer(); u8g2.setFont(u8g2_font_helvB08_tr); sprintf(buffer, "Pulse: %u x 1/16us", pulseLength); u8g2.drawStr(15, 64, buffer); sprintf(buffer,"min: %u", min); u8g2.drawStr(0, 10, buffer); sprintf(buffer,"max: %u", max); u8g2.drawStr(80, 10, buffer); u8g2.sendBuffer(); delay(100); } // function to query the pulse length ISR uint16_t measurePulseLength() { uint16_t sum = 0; uint16_t pulseLength; for(byte i=0; i falling) ) }