Skip to content

Commit 797abb5

Browse files
authored
Update SimpleTone.ino (#552)
Adds code to define which pins are used, moving them from the defaults, which are the same as the only three analogue input pins, and adding comments to explain how to change them. The original didn't give any clues about which pins were used, which isn't ideal for a beginner - it was necessary to look at the code for the library, to work that out. The new code redundantly defines a pWS pin number (as pBCLK+1), which isn't used in the example, but is meant as a reminder to the person using it, of how to wire up WS.
1 parent ffff21a commit 797abb5

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

libraries/I2S/examples/SimpleTone/SimpleTone.ino

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,59 @@
66
created 17 November 2016
77
by Sandeep Mistry
88
modified for ESP8266 by Earle F. Philhower, III <[email protected]>
9+
10+
11+
Only 16 bitsPerSample are allowed by the PIO code. Only write, no read.
12+
13+
bool setBCLK(pin_size_t pin); // Must be 28 or less. Default is 26
14+
// This assigns two adjacent pins - the pin after this one (one greater) is the WS (word select) signal,
15+
// which toggles before the sample for each channel is sent
16+
17+
bool setDOUT(pin_size_t pin); // Must be 29 or less. Default is 28
18+
19+
920
*/
1021

1122
#include <I2S.h>
1223

24+
// GPIO pin numbers
25+
26+
//define pBCLK 26
27+
#define pBCLK 20
28+
#define pWS (pBCLK+1)
29+
//define pDOUT 28
30+
#define pDOUT 22
31+
1332
const int frequency = 440; // frequency of square wave in Hz
1433
const int amplitude = 500; // amplitude of square wave
15-
const int sampleRate = 8000; // sample rate in Hz
34+
//const int sampleRate = 8000; // sample rate in Hz
35+
const int sampleRate = 16000; // minimum for UDA1334A
1636

1737
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
1838

1939
short sample = amplitude; // current sample value
2040
int count = 0;
2141

42+
2243
void setup() {
23-
Serial.begin(115200);
44+
pinMode(LED_BUILTIN, OUTPUT);
45+
digitalWrite(LED_BUILTIN, 1);
46+
47+
Serial.begin(9600);
2448
Serial.println("I2S simple tone");
2549

50+
I2S.setBCLK(pBCLK); // Must be 28 or less. Default is 26
51+
// This assigns two adjacent pins - the pin after this one (one greater) is the WS (word select) signal,
52+
// which toggles before the sample for each channel is sent
53+
54+
I2S.setDOUT(pDOUT); // Must be 29 or less. Default is 28
55+
2656
// start I2S at the sample rate with 16-bits per sample
2757
if (!I2S.begin(sampleRate)) {
2858
Serial.println("Failed to initialize I2S!");
2959
while (1); // do nothing
3060
}
61+
3162
}
3263

3364
void loop() {
@@ -43,4 +74,3 @@ void loop() {
4374
// increment the counter for the next sample
4475
count++;
4576
}
46-

0 commit comments

Comments
 (0)