8000 Merge pull request #1245 from arduino/sync/Hannes7eicher/UNO-R4-WiFi-… · manishcoder2212/docs-content@3dfef8a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3dfef8a

Browse files
Merge pull request arduino#1245 from arduino/sync/Hannes7eicher/UNO-R4-WiFi-CodeBlock
[MKC-1048] Add UNO R4 WiFi CodeBlocks
2 parents 6ac8e87 + cd3dc8a commit 3dfef8a

File tree

7 files changed

+38
-1782
lines changed

7 files changed

+38
-1782
lines changed

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/adc-resolution/adc-resolution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ tags:
55
- ADC
66
- 14-bit
77
author: 'Karl Söderby'
8+
hardware:
9+
- hardware/02.hero/boards/uno-r4-wifi
810
---
911

1012
In this tutorial you will learn how to change the analog-to-digital converter (ADC) on an **Arduino UNO R4 WiFi** board. By default, the resolution is set to 10-bit, which can be updated to both 12-bit (0-4096) and 14-bit (0-16383) resolutions for improved accuracy on analog readings.

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/can/can.md

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: 'Learn how to send messages using the CAN bus on the UNO R4 WiFi.'
44
tags:
55
- CAN
66
author: 'Karl Söderby'
7+
hardware:
8+
- hardware/02.hero/boards/uno-r4-wifi
79
---
810

911
In this tutorial you will learn how to use the CAN controller on the **Arduino UNO R4 WiFi** board. The CAN controller is embedded in the UNO R4 WiFi's microcontroller (RA4M1). CAN is a serial protocol that is mainly used in the automotive industry.
@@ -25,7 +27,7 @@ The goals of this tutorial are:
2527
- CAN transceiver module *
2628
- Jumper wires
2729

28-
* In this tutorial, we are using a SN65HVD230 breakout module.
30+
\* In this tutorial, we are using a SN65HVD230 breakout module.
2931

3032
## Controller Area Network (CAN)
3133

@@ -79,80 +81,13 @@ CanMsg msg(CAN_ID, sizeof(msg_data), msg_data);
7981

8082
After you have crafted a CAN message, we can send it off, by using the `CAN.write()` method. The following example creates a CAN message that increases each time `void loop()` is executed.
8183

82-
```arduino
83-
#include <Arduino_CAN.h>
84-
85-
static uint32_t const CAN_ID = 0x20;
86-
87-
void setup()
88-
{
89-
Serial.begin(115200);
90-
while (!Serial) { }
91-
92-
if (!CAN.begin(CanBitRate::BR_250k))
93-
{
94-
Serial.println("CAN.begin(...) failed.");
95-
for (;;) {}
96-
}
97-
}
98-
99-
static uint32_t msg_cnt = 0;
100-
101-
void loop()
102-
{
103-
/* Assemble a CAN message with the format of
104-
* 0xCA 0xFE 0x00 0x00 [4 byte message counter]
105-
*/
106-
uint8_t const msg_data[] = {0xCA,0xFE,0,0,0,0,0,0};
107-
memcpy((void *)(msg_data + 4), &msg_cnt, sizeof(msg_cnt));
108-
CanMsg msg(CAN_ID, sizeof(msg_data), msg_data);
109-
110-
/* Transmit the CAN message, capture and display an
111-
* error core in case of failure.
112-
*/
113-
if (int const rc = CAN.write(msg); rc < 0)
114-
{
115-
Serial.print ("CAN.write(...) failed with error code ");
116-
Serial.println(rc);
117-
for (;;) { }
118-
}
119-
120-
/* Increase the message counter. */
121-
msg_cnt++;
122-
123-
/* Only send one message per second. */
124-
delay(1000);
125-
}
126-
```
84+
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino" className="arduino"/>
12785

12886
### CAN Read
12987

13088
To read an incoming CAN message, first use `CAN.available()` to check if data is available, before using `CAN.read()` to read the message.
13189

132-
```arduino
133-
#include <Arduino_CAN.h>
134-
135-
void setup()
136-
{
137-
Serial.begin(115200);
138-
while (!Serial) { }
139-
140-
if (!CAN.begin(CanBitRate::BR_250k))
141-
{
142-
Serial.println("CAN.begin(...) failed.");
143-
for (;;) {}
144-
}
145-
}
146-
147-
void loop()
148-
{
149-
if (CAN.available())
150-
{
151-
CanMsg const msg = CAN.read();
152-
Serial.println(msg);
153-
}
154-
}
155-
```
90+
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/Arduino_CAN/examples/CANRead/CANRead.ino" className="arduino"/>
15691

15792
## Summary
15893

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/dac/dac.md

Lines changed: 5 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,7 @@ The waveform is being stored as samples in an array, and with every loop of the
5454

5555
Open a new sketch and paste the following code into your window.
5656

57-
```arduino
58-
#include "analogWave.h"
59-
60-
analogWave wave(DAC);
61-
62-
int freq = 10; // in hertz, change accordingly
63-
64-
void setup() {
65-
Serial.begin(115200);
66-
pinMode(A5, INPUT);
67-
wave.sine(freq);
68-
}
69-
70-
void loop() {
71-
freq = map(analogRead(A5), 0, 1024, 0, 10000);
72-
Serial.println("Frequency is now " + String(freq) + " hz");
73-
wave.freq(freq);
74-
delay(1000);
75-
}
76-
```
57+
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/AnalogWave/examples/SineWave/SineWave.ino" className="arduino"/>
7758

7859
## Testing It Out
7960
Once you have uploaded the code to the board, it should start generating a sine wave oscillation on the DAC, that depending on the frequency could be used to produce sound on a piezo buzzer or speaker. If you have an oscilloscope at hand, connecting its probe to the DAC output might be an interesting exercise so see what the wave looks like.
@@ -87,149 +68,12 @@ Now that you know your setup is working, you can experiment further with differe
8768
### Frere Jacques
8869

8970
This one for example plays the melody of Frere Jacques:
90-
```arduino
91-
/*
92-
DAC Melody player
93-
94-
Generates a series of tones from MIDI note values
95-
using the Uno R4 DAC and the AnalogWave Library.
96-
The melody is "Frere Jacques"
97-
98-
circuit:
99-
* audio amp (LM386 used for testing) input+ attached to A0
100-
* audio amp input- attached to ground
101-
* 4-8-ohm speaker attached to amp output+
102-
* Potentiometer connected to pin A5
103-
104-
created 13 Feb 2017
105-
modified 3 Jul 2023
106-
by Tom Igoe
107-
*/
108-
#include "analogWave.h"
109-
analogWave wave(DAC);
110-
111-
#define NOTE_A4 69 // MIDI note value for middle A
112-
#define FREQ_A4 440 // frequency for middle A
113-
114-
// the tonic, or first note of the key signature for the song:
115-
int tonic = 65;
116-
// the melody sequence. Note values are relative to the tonic:
117-
int melody[] = {1, 3, 5, 1,
118-
1, 3, 5, 1,
119-
5, 6, 8, 5, 6, 8,
120-
8, 10, 8, 6, 5, 1,
121-
8, 10, 8, 6, 5, 1,
122-
1, -4, 1,
123-
1, -4, 1
124-
};
125-
// the rhythm sequence. Values are 1/note, e.g. 4 = 1/4 note:
126-
int rhythm[] = {4, 4, 4, 4,
127-
4, 4, 4, 4,
128-
4, 4, 2,
129-
4, 4, 2,
130-
8, 8, 8, 8, 4, 4,
131-
8, 8, 8, 8, 4, 4,
132-
4, 4, 2,
133-
4, 4, 2
134-
};
135-
// which note of the melody to play:
136-
int noteCounter = 0;
137-
138-
int bpm = 120; // beats per minute
139-
// duration of a beat in ms
140-
float beatDuration = 60.0 / bpm * 1000;
141-
142-
void setup() {
143-
// start the sine wave generator:
144-
wave.sine(10);
145-
}
146-
147-
void loop() {
148-
// current note is an element of the array:
149-
int currentNote = melody[noteCounter] + tonic;
150-
// play a note from the melody:
151-
// convert MIDI note number to frequency:
152-
float frequency = FREQ_A4 * pow(2, ((currentNote - NOTE_A4) / 12.0));
153-
154-
// all the notes in this are sixteenth notes,
155-
// which is 1/4 of a beat, so:
156-
float noteDuration = beatDuration * (4.0 / rhythm[noteCounter]);
157-
// turn the note on:
158-
wave.freq(frequency);
159-
// tone(speakerPin, frequency, noteDuration * 0.85);
160-
// keep it on for the appropriate duration:
161-
delay(noteDuration * 0.85);
162-
wave.stop();
163-
delay(noteDuration * 0.15);
164-
// turn the note off:
165-
// noTone(speakerPin);
166-
// increment the note number for next time through the loop:
167-
noteCounter++;
168-
// keep the note in the range from 0 - 32 using modulo:
169-
noteCounter = noteCounter % 32;
170-
171-
}
172-
```
71+
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/AnalogWave/examples/DACJacques/DACJacques.ino" className="arduino"/>
17372

17473
### MIDI Piano Notes
175-
This sketch will break down the potentiometer input to steps, that are translated to the 88 MIDI notes that represent the keys on a piano.
176-
177-
```arduino
178-
/*
179-
Plays a tone in response to a potentiometer
180-
formula from https://newt.phys.unsw.edu.au/jw/notes.html
181-
and https://en.wikipedia.org/wiki/MIDI_tuning_standard:
182-
183-
the MIDI protocol divides the notes of an equal-tempered scale into
184-
128 possible note values. Middle A is MIDI note value 69. There is
185-
a formula for converting MIDI note numbers (0-127) to pitches. This sketch
186-
reduces that to the notes 21 - 108, which are the 88 keys found on a piano:
187-
188-
frequency = 440 * ((noteNumber - 69) / 12.0)^2
189-
190-
You can see this applied in the code below.
191-
192-
circuit:
193-
* audio amp (LM386 used for testing) input+ attached to A0
194-
* audio amp input- attached to ground
195-
* 4-8-ohm speaker attached to amp output+
196-
* Potentiometer connected to pin A5
197-
198-
created 18 Dec 2018
199-
modified 3 Jul 2023
200-
by Tom Igoe
201-
*/
202-
203-
// include the AnalogWave library:
204-
#include "analogWave.h"
205-
analogWave wave(DAC);
206-
207-
// middle A is the reference frequency for an
208-
// equal-tempered scale. Set its frequency and note value:
209-
#define NOTE_A4 69 // MIDI note value for middle A
210-
#define FREQ_A4 440 // frequency for middle A
211-
212-
const int speakerPin = A0; // the pin number for the speaker
213-
void setup() {
214-
Serial.begin(9600);
215-
wave.sine(10);
216-
}
217-
void loop() {
218-
// convert sensor reading to 21 - 108 range
219-
// which is the range of MIDI notes on an 88-key keyboard
220-
// (from A0 to C8):
221-
int sensorReading = analogRead(A5);
222-
int noteValue = map(sensorReading, 0, 1023, 21, 108);
223-
// then convert to frequency:
224-
float frequency = FREQ_A4 * pow(2, ((noteValue - NOTE_A4) / 12.0));
225-
int freq = int(frequency);
226-
// turn the speaker on:
227-
wave.freq(freq);
228-
Serial.print("note value: "+ String(noteValue) + " freq: ");
229-
Serial.println(freq);
230-
delay(500);
231-
}
232-
```
74+
This sketch will break down the potentiometer input into steps, that are translated to the 88 MIDI notes that represent the keys on a piano.
75+
76+
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/AnalogWave/examples/DACEqualTemperedScale/DACEqualTemperedScale.ino" className="arduino"/>
23377

23478
## Conclusion
23579
By following this tutorials you've experimented with the DAC on the Arduino UNO R4 boards and used it to first generate a sine wave, and then to explore the possibilities of analog output by testing out various examples.

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/eeprom/eeprom.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ tags:
55
- RTC
66
- Alarm
77
author: 'Karl Söderby'
8+
hardware:
9+
- hardware/02.hero/boards/uno-r4-wifi
810
---
911

1012
In this tutorial you will learn how to access the EEPROM (memory) on an **Arduino UNO R4 WiFi** board. The EEPROM is embedded in the UNO R4 WiFi's microcontroller (RA4M1).
@@ -42,7 +44,7 @@ EEPROM.read(0); //reads first byte
4244

4345
There are several more methods available when working with EEPROM, and you can read more about this in the [A Guide to EEPROM](https://docs.arduino.cc/learn/programming/eeprom-guide).
4446

45-
***Please note: EEPROM is a type of memory with limited amount of write cycles. Be cautious when writing to this memory as you may significantly reduce the lifespan of this memory.***
47+
***Please note: EEPROM is a type of memory with a limited amount of write cycles. Be cautious when writing to this memory as you may significantly reduce the lifespan of this memory.***
4648

4749
### EEPROM Write
4850

@@ -55,31 +57,31 @@ int addr = 0;
5557
byte value = 100;
5658
5759
void setup() {
58-
EEPROM.write(addr, val);
60+
EEPROM.write(addr, value);
5961
}
6062
void loop(){
6163
}
6264
```
6365

6466
### EEPROM Read
6567

66-
A minimal example on how to **read** from the EEPROM can be found below:
68+
A minimal example of how to **read** from the EEPROM can be found below:
6769

6870
```arduino
6971
#include <EEPROM.h>
7072
71-
int address = 0;
73+
int addr = 0;
7274
byte value;
7375
7476
void setup() {
7577
Serial.begin(9600);
7678
value = EEPROM.read(addr);
7779
while (!Serial) {
78-
;
80+
7981
}
8082
8183
Serial.print("Address 0: ");
82-
Serial.println(addr);
84+
Serial.println(value);
8385
}
8486
8587
void loop() {

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/r4-wifi-getting-started/r4-wifi-getting-started.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Getting Started with UNO R4 WiFi
33
description: A step-by-step guide to install the board package needed for the UNO R4 WiFi board.
44
author: Hannes Siebeneicher
5+
hardware:
6+
- hardware/02.hero/boards/uno-r4-wifi
57
tags: [UNO R4 WiFi, Installation, IDE]
68
---
79

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/rtc/rtc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ tags:
55
- RTC
66
- Alarm
77
author: 'Karl Söderby'
8+
hardware:
9+
- hardware/02.hero/boards/uno-r4-wifi
810
---
911

1012
In this tutorial you will learn how to access the real-time clock (RTC) on an **Arduino UNO R4 WiFi** board. The RTC is embedded in the UNO R4 WiFi's microcontroller (RA4M1).

0 commit comments

Comments
 (0)
0