├── LICENSE ├── R4Minima_serial_no_usb └── R4Minima_serial_no_usb.ino ├── R4WiFi_led_matrix └── R4WiFi_led_matrix.ino ├── R4_SineWave └── R4_SineWave.ino └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Clemens @ Elektor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R4Minima_serial_no_usb/R4Minima_serial_no_usb.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Purpose: Try routing Serial to pins 0 & 1. 3 | * Board: UNO R4 4 | * IDE: 1.8.19 5 | * 6 | * Usage: 7 | * 8 | * By: Clemens Valens 9 | * Date: 26/6/2023 10 | */ 11 | 12 | // Uncomment to route Serial to pins 0 & 1. 13 | #define NO_USB 14 | #include 15 | 16 | void setup(void) 17 | { 18 | Serial.begin(9600); 19 | #ifndef NO_USB 20 | Serial1.begin(9600); 21 | #endif 22 | } 23 | 24 | void loop(void) 25 | { 26 | Serial.write('$'); // TX on pin 1 if NO_USB is defined 27 | #ifndef NO_USB 28 | Serial1.write('<'); // TX on pin 1 if NO_USB is not defined 29 | #endif 30 | delay(20); 31 | } 32 | -------------------------------------------------------------------------------- /R4WiFi_led_matrix/R4WiFi_led_matrix.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Purpose: Display a text message scrolling from right to left 3 | * on the board's 8x12 LED matrix. 4 | * Board: Arduino UNO R4 WiFi 5 | * IDE: 1.8.19 with "Arduino Renesas Boards" version 0.8.5-ea 6 | * 7 | * Usage: Upload to the board and enjoy. 8 | * 9 | * Provides many possibilities for doing things better and more efficiently. 10 | * Parts of this code work because of the way the display works. For instance, 11 | * there is no need to draw black pixels, only white pixels need drawing. 12 | * Naively porting this code to another kind of display will probably not work. 13 | * Buffer overflow protection is probably flawed, so don't count on it. 14 | * 15 | * By: Clemens Valens, Elektor 16 | * Date: 14/6/2023 17 | */ 18 | 19 | // Leading spaces ensure starting at the right. 20 | uint8_t banner_text[] = " Arduino UNO R4 WiFi"; 21 | 22 | // First value is the width of a character in columns. This allows for 23 | // easy tight spacing on the display (TTF kind of thing). 24 | const uint8_t font_5x8[] = 25 | { 26 | 3, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // space 27 | 1, 0b01011111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // ! 28 | 3, 0b00000011, 0b00000000, 0b00000011, 0b00000000, 0b00000000, // " 29 | 5, 0b00010100, 0b00111110, 0b00010100, 0b00111110, 0b00010100, // # 30 | 4, 0b00100100, 0b01101010, 0b00101011, 0b00010010, 0b00000000, // $ 31 | 5, 0b01100011, 0b00010011, 0b00001000, 0b01100100, 0b01100011, // % 32 | 5, 0b00110110, 0b01001001, 0b01010110, 0b00100000, 0b01010000, // & 33 | 1, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // ' 34 | 3, 0b00011100, 0b00100010, 0b01000001, 0b00000000, 0b00000000, // ( 35 | 3, 0b01000001, 0b00100010, 0b00011100, 0b00000000, 0b00000000, // ) 36 | 5, 0b00101000, 0b00011000, 0b00001110, 0b00011000, 0b00101000, // * 37 | 5, 0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000, // + 38 | 2, 0b10110000, 0b01110000, 0b00000000, 0b00000000, 0b00000000, // , 39 | 4, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000000, // - 40 | 2, 0b01100000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, // . 41 | 4, 0b01100000, 0b00011000, 0b00000110, 0b00000001, 0b00000000, // / 42 | 4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // 0 43 | 3, 0b01000010, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // 1 44 | 4, 0b01100010, 0b01010001, 0b01001001, 0b01000110, 0b00000000, // 2 45 | 4, 0b00100010, 0b01000001, 0b01001001, 0b00110110, 0b00000000, // 3 46 | 4, 0b00011000, 0b00010100, 0b00010010, 0b01111111, 0b00000000, // 4 47 | 4, 0b00100111, 0b01000101, 0b01000101, 0b00111001, 0b00000000, // 5 48 | 4, 0b00111110, 0b01001001, 0b01001001, 0b00110000, 0b00000000, // 6 49 | 4, 0b01100001, 0b00010001, 0b00001001, 0b00000111, 0b00000000, // 7 50 | 4, 0b00110110, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // 8 51 | 4, 0b00000110, 0b01001001, 0b01001001, 0b00111110, 0b00000000, // 9 52 | 2, 0b01010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // : 53 | 2, 0b10000000, 0b01010000, 0b00000000, 0b00000000, 0b00000000, // ; 54 | 3, 0b00010000, 0b00101000, 0b01000100, 0b00000000, 0b00000000, // < 55 | 3, 0b00010100, 0b00010100, 0b00010100, 0b00000000, 0b00000000, // = 56 | 3, 0b01000100, 0b00101000, 0b00010000, 0b00000000, 0b00000000, // > 57 | 4, 0b00000010, 0b01011001, 0b00001001, 0b00000110, 0b00000000, // ? 58 | 5, 0b00111110, 0b01001001, 0b01010101, 0b01011101, 0b00001110, // @ 59 | 4, 0b01111110, 0b00010001, 0b00010001, 0b01111110, 0b00000000, // A 60 | 4, 0b01111111, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // B 61 | 4, 0b00111110, 0b01000001, 0b01000001, 0b00100010, 0b00000000, // C 62 | 4, 0b01111111, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // D 63 | 4, 0b01111111, 0b01001001, 0b01001001, 0b01000001, 0b00000000, // E 64 | 4, 0b01111111, 0b00001001, 0b00001001, 0b00000001, 0b00000000, // F 65 | 4, 0b00111110, 0b01000001, 0b01001001, 0b01111010, 0b00000000, // G 66 | 4, 0b01111111, 0b00001000, 0b00001000, 0b01111111, 0b00000000, // H 67 | 3, 0b01000001, 0b01111111, 0b01000001, 0b00000000, 0b00000000, // I 68 | 4, 0b00110000, 0b01000000, 0b01000001, 0b00111111, 0b00000000, // J 69 | 4, 0b01111111, 0b00001000, 0b00010100, 0b01100011, 0b00000000, // K 70 | 4, 0b01111111, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // L 71 | 5, 0b01111111, 0b00000010, 0b00001100, 0b00000010, 0b01111111, // M 72 | 5, 0b01111111, 0b00000100, 0b00001000, 0b00010000, 0b01111111, // N 73 | 4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // O 74 | 4, 0b01111111, 0b00001001, 0b00001001, 0b00000110, 0b00000000, // P 75 | 4, 0b00111110, 0b01000001, 0b01000001, 0b10111110, 0b00000000, // Q 76 | 4, 0b01111111, 0b00001001, 0b00001001, 0b01110110, 0b00000000, // R 77 | 4, 0b01000110, 0b01001001, 0b01001001, 0b00110010, 0b00000000, // S 78 | 5, 0b00000001, 0b00000001, 0b01111111, 0b00000001, 0b00000001, // T 79 | 4, 0b00111111, 0b01000000, 0b01000000, 0b00111111, 0b00000000, // U 80 | 5, 0b00001111, 0b00110000, 0b01000000, 0b00110000, 0b00001111, // V 81 | 5, 0b00111111, 0b01000000, 0b00111000, 0b01000000, 0b00111111, // W 82 | 5, 0b01100011, 0b00010100, 0b00001000, 0b00010100, 0b01100011, // X 83 | 5, 0b00000111, 0b00001000, 0b01110000, 0b00001000, 0b00000111, // Y 84 | 4, 0b01100001, 0b01010001, 0b01001001, 0b01000111, 0b00000000, // Z 85 | 2, 0b01111111, 0b01000001, 0b00000000, 0b00000000, 0b00000000, // [ 86 | 4, 0b00000001, 0b00000110, 0b00011000, 0b01100000, 0b00000000, // '\' 87 | 2, 0b01000001, 0b01111111, 0b00000000, 0b00000000, 0b00000000, // ] 88 | 3, 0b00000010, 0b00000001, 0b00000010, 0b00000000, 0b00000000, // hat 89 | 4, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // _ 90 | 2, 0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000, // ` 91 | 4, 0b00100000, 0b01010100, 0b01010100, 0b01111000, 0b00000000, // a 92 | 4, 0b01111111, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // b 93 | 4, 0b00111000, 0b01000100, 0b01000100, 0b00000000, 0b00000000, // c 94 | 4, 0b00111000, 0b01000100, 0b01000100, 0b01111111, 0b00000000, // d 95 | 4, 0b00111000, 0b01010100, 0b01010100, 0b00011000, 0b00000000, // e 96 | 3, 0b00000100, 0b01111110, 0b00000101, 0b00000000, 0b00000000, // f 97 | 4, 0b10011000, 0b10100100, 0b10100100, 0b01111000, 0b00000000, // g 98 | 4, 0b01111111, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // h 99 | 3, 0b01000100, 0b01111101, 0b01000000, 0b00000000, 0b00000000, // i 100 | 4, 0b01000000, 0b10000000, 0b10000100, 0b01111101, 0b00000000, // j 101 | 4, 0b01111111, 0b00010000, 0b00101000, 0b01000100, 0b00000000, // k 102 | 3, 0b01000001, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // l 103 | 5, 0b01111100, 0b00000100, 0b01111100, 0b00000100, 0b01111000, // m 104 | 4, 0b01111100, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // n 105 | 4, 0b00111000, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // o 106 | 4, 0b11111100, 0b00100100, 0b00100100, 0b00011000, 0b00000000, // p 107 | 4, 0b00011000, 0b00100100, 0b00100100, 0b11111100, 0b00000000, // q 108 | 4, 0b01111100, 0b00001000, 0b00000100, 0b00000100, 0b00000000, // r 109 | 4, 0b01001000, 0b01010100, 0b01010100, 0b00100100, 0b00000000, // s 110 | 3, 0b00000100, 0b00111111, 0b01000100, 0b00000000, 0b00000000, // t 111 | 4, 0b00111100, 0b01000000, 0b01000000, 0b01111100, 0b00000000, // u 112 | 5, 0b00011100, 0b00100000, 0b01000000, 0b00100000, 0b00011100, // v 113 | 5, 0b00111100, 0b01000000, 0b00111100, 0b01000000, 0b00111100, // w 114 | 5, 0b01000100, 0b00101000, 0b00010000, 0b00101000, 0b01000100, // x 115 | 4, 0b10011100, 0b10100000, 0b10100000, 0b01111100, 0b00000000, // y 116 | 3, 0b01100100, 0b01010100, 0b01001100, 0b00000000, 0b00000000, // z 117 | 3, 0b00001000, 0b00110110, 0b01000001, 0b00000000, 0b00000000, // { 118 | 1, 0b01111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // | 119 | 3, 0b01000001, 0b00110110, 0b00001000, 0b00000000, 0b00000000, // } 120 | 4, 0b00001000, 0b00000100, 0b00001000, 0b00000100, 0b00000000, // ~ 121 | }; 122 | 123 | // LED matrix info. 124 | const uint8_t led_matrix_pin_first = 28; 125 | const uint8_t led_matrix_pin_last = 38; 126 | const uint8_t led_matrix_pin_count = led_matrix_pin_last - led_matrix_pin_first + 1; 127 | const uint8_t led_matrix_rows = 8; 128 | const uint8_t led_matrix_cols = 12; 129 | 130 | // Pixel-to-pin translation table. 131 | // A HEX value encodes two pin numbers. The MSB is to be driven LOW, 132 | // the LSB is to be driven HIGH. 133 | // Example: pixel (4,2) contains the value 0x60, meaning that pin 6 must 134 | // be driven low and pin 0 must be driven high to activate the pixel. 135 | // The pin number is an offset to the constant led_matrix_pin_first 136 | // Note that they all appear in pairs, so you could make the table 50% 137 | // smaller at the cost of doing some swapping for odd or even columns. 138 | // (0,0) is upper left corner when the board's USB connector points to the left. 139 | const uint8_t led_matrix_pins[led_matrix_rows][led_matrix_cols] = 140 | { 141 | // 0 1 2 3 4 5 6 7 8 9 10 11 142 | { 0x37, 0x73, 0x47, 0x74, 0x43, 0x34, 0x87, 0x78, 0x83, 0x38, 0x84, 0x48 }, // 0 143 | { 0x07, 0x70, 0x03, 0x30, 0x04, 0x40, 0x08, 0x80, 0x67, 0x76, 0x63, 0x36 }, // 1 144 | { 0x64, 0x46, 0x68, 0x86, 0x60, 0x06, 0x57, 0x75, 0x53, 0x35, 0x54, 0x45 }, // 2 145 | { 0x58, 0x85, 0x50, 0x05, 0x56, 0x65, 0x17, 0x71, 0x13, 0x31, 0x14, 0x41 }, // 3 146 | { 0x18, 0x81, 0x10, 0x01, 0x16, 0x61, 0x15, 0x51, 0x27, 0x72, 0x23, 0x32 }, // 4 147 | { 0x24, 0x42, 0x28, 0x82, 0x20, 0x02, 0x26, 0x62, 0x25, 0x52, 0x21, 0x12 }, // 5 148 | { 0xa7, 0x7a, 0xa3, 0x3a, 0xa4, 0x4a, 0xa8, 0x8a, 0xa0, 0x0a, 0xa6, 0x6a }, // 6 149 | { 0xa5, 0x5a, 0xa1, 0x1a, 0xa2, 0x2a, 0x97, 0x79, 0x93, 0x39, 0x94, 0x49 }, // 7 150 | }; 151 | 152 | // Every byte represents a column of the LED matrix. 153 | // Can hold 32 5x8-font characters. 154 | // Buffer can be smaller at the price of more code. 155 | uint8_t led_matrix_buffer[5*32]; 156 | 157 | // Activate the pixel at (x,y) for ontime microseconds. 158 | void put_pixel(uint8_t x, uint8_t y, uint32_t ontime) 159 | { 160 | uint8_t pins = led_matrix_pins[y][x]; 161 | uint8_t l = (pins>>4) + led_matrix_pin_first; 162 | uint8_t h = (pins&0xf) + led_matrix_pin_first; 163 | pinMode(l,OUTPUT); 164 | digitalWrite(l,LOW); 165 | pinMode(h,OUTPUT); 166 | digitalWrite(h,HIGH); 167 | // If ontime = 0, pixel remains active until it is deactivated 168 | // by another put_pixel that happens to use the same pin(s). 169 | if (ontime!=0) 170 | { 171 | delayMicroseconds(ontime); 172 | pinMode(l,INPUT); 173 | pinMode(h,INPUT); 174 | } 175 | } 176 | 177 | // Call periodically at desired fps rate. 178 | // ontime specifies how long a pixel remains on. 179 | void led_matrix_buffer_show(uint32_t x_offset, uint32_t ontime) 180 | { 181 | for (uint8_t i=0; i=sizeof(led_matrix_buffer)) return; 184 | uint8_t col = led_matrix_buffer[i+x_offset]; 185 | for (uint8_t row=0; row>= 1; 192 | } 193 | } 194 | } 195 | 196 | // Write a character to the buffer. 197 | uint8_t led_matrix_putch(uint8_t *p_buffer, uint16_t buffer_size, uint8_t ch) 198 | { 199 | uint8_t i; 200 | 201 | if (ch<' ') return 0; 202 | ch -= ' '; 203 | uint16_t offset = 6*ch; 204 | uint8_t width = font_5x8[offset]; 205 | for (i=0; i=buffer_size) break; 210 | p_buffer[i] = font_5x8[offset]; 211 | } 212 | return i+1; 213 | } 214 | 215 | // Write a string to the buffer. 216 | uint16_t led_matrix_puts(uint8_t *p_buffer, uint16_t buffer_size, uint8_t *p_str) 217 | { 218 | uint8_t *p = p_buffer; 219 | while (*p_str!=0) 220 | { 221 | p += led_matrix_putch(p,buffer_size-(p-p_buffer),*p_str); 222 | p_str++; 223 | } 224 | return p - p_buffer; 225 | } 226 | 227 | uint32_t t_prev = 0; 228 | 229 | void setup(void) 230 | { 231 | // Initialize LED matrix pins. 232 | for (uint8_t i=0; i=t_prev+scroll_speed) 255 | { 256 | t_prev = millis(); 257 | scroll += 1; // Scroll to the left. 258 | if (scroll>5*strlen((char*)banner_text)) scroll = 0; // restart 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /R4_SineWave/R4_SineWave.ino: -------------------------------------------------------------------------------- 1 | #include "analogWave.h" 2 | 3 | analogWave wave(DAC); 4 | 5 | int freq = 1000; // in hertz, change accordingly 6 | const int freq_ctrl_pin_vcc = A3; 7 | const int freq_ctrl_pin = A4; 8 | const int freq_ctrl_pin_gnd = A5; 9 | 10 | void setup(void) 11 | { 12 | Serial.begin(115200); 13 | pinMode(freq_ctrl_pin_gnd, OUTPUT); 14 | digitalWrite(freq_ctrl_pin_gnd,LOW); 15 | pinMode(freq_ctrl_pin_vcc, OUTPUT); 16 | digitalWrite(freq_ctrl_pin_vcc,HIGH); 17 | wave.sine(freq); 18 | } 19 | 20 | void loop(void) 21 | { 22 | freq = map(analogRead(freq_ctrl_pin), 0, 1024, 0, 10000); 23 | Serial.println("Frequency is now " + String(freq) + " Hz"); 24 | wave.freq(freq); 25 | delay(100); 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-UNO-R4 2 | Exploring UNO R4 Minima & WiFi features. 3 | 4 | On the UNO R4, Serial is the USB port, Serial1 is on pins 0 & 1. 5 | 6 | Put 7 | ``` 8 | #define NO_USB 9 | #include 10 | ``` 11 | at the top of the sketch to route Serial to pins 0 and 1. 12 | 13 | On the WiFi Serial2 is connected to the Wi-Fi module. 14 | --------------------------------------------------------------------------------