Page 8 of 16
Page 167
Use GPIO 5, 6, 7 and 8 for the Arduino NANO ESP32
Change SPI.begin(14, 12, 13, 15); to SPI.begin(7, 5, 6, 8); and all references to GPIO15 to GPIO8.
Connect pin 12 to 13 for the ESP and 5 to 6 for the NANO ESP32
#include <SPI.h>
void setup() {
pinMode(15, OUTPUT);
digitalWrite(15, 1);
SPI.begin(14, 12, 13, 15);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
Serial.begin(9600);
}
void loop() {
digitalWrite(15, 0);
char receivedVal = SPI.transfer(0xAA);
digitalWrite(15, 1);
Serial.println(receivedVal,HEX);
delay(1000);
}
Page 174
Use GPIO 5, 6, 7 and 8 for the Arduino NANO ESP32
Change SPI.begin(14, 12, 13, 15); to SPI.begin(7, 5, 6, 8); and all references to GPIO15 to GPIO8.
#include <SPI.h>
void setup() {
pinMode(15, OUTPUT);
digitalWrite(15, 1);
SPI.begin(14, 12, 13, 15);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
Serial.begin(9600);
}
char data[3];
void loop() {
data[0] = 0x01;
data[1] = 0x80;
data[2] = 0x00;
digitalWrite(15, 0);
SPI.transfer(data,3);
digitalWrite(15, 1);
int raw = (data[1] & 0x03) << 8 |data[2];
Serial.println(raw);
float volts=raw*3.3/1023.0;
Serial.println(volts);
delay(1000);
}
Page175
Use GPIO 5, 6, 7 and 8 for the Arduino NANO ESP32
Change SPI.begin(14, 12, 13, 15); to SPI.begin(7, 5, 6, 8); and all references to GPIO15 to GPIO8.
#include <SPI.h>
float readADC(uint8_t chan) {
char data[3];
data[0] = 0x01;
data[1] = (0x08 | chan) << 4;
data[2] = 0x00;
digitalWrite(15, 0);
SPI.transfer(data, 3);
digitalWrite(15, 1);
int raw = (data[1] & 0x03) << 8 | data[2];
float volts = raw * 3.3 / 1023.0;
return volts;
}
void setup() {
pinMode(15, OUTPUT);
digitalWrite(15, 1);
SPI.begin(14, 12, 13, 15);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
Serial.begin(9600);
}
void loop() {
float volts = readADC(0);
Serial.println(volts);
delay(1000);
}