Skip to content

Commit

Permalink
update sample code without actual testing it
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdyscout committed Oct 31, 2022
1 parent 7b005a0 commit 9d81802
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
example:
- examples/analogRead_Mux/analogRead_Mux.ino
- examples/analogRead_Scan/analogRead_Scan.ino
- examples/analogRead_ContinuousScan/analogRead_ContinuousScan.ino
- examples/analogRead_Scan_Differential/analogRead_Scan_Differential.ino
- examples/analogReadContinuous_Scan/analogReadContinuous_Scan.ino
steps:
- uses: actions/checkout@v2
- name: Cache pip
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
examples:
- examples/analogRead_Mux/analogRead_Mux.ino
- examples/analogRead_Scan/analogRead_Scan.ino
- examples/analogRead_ContinuousScan/analogRead_ContinuousScan.ino
- examples/analogRead_Scan_Differential/analogRead_Scan_Differential.ino
- examples/analogReadContinuous_Scan/analogReadContinuous_Scan.ino
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void setup() {
;
}
mcp.enableScanChannel(MCP_CH0);
mcp.enableScanChannel(MCP_CH1);
mcp.startContinuous();

Serial.println("MCP setup done");
Expand All @@ -58,16 +59,16 @@ void loop() {

// read the input on default analog channel:
int32_t adcdata0 = mcp.analogReadContinuous(MCP_CH0);
// int32_t adcdata1 = mcp.analogReadContinuous(MCP_CH1);
int32_t adcdata1 = mcp.analogReadContinuous(MCP_CH1);

// Convert the analog reading
double voltage0 = adcdata0 * mcp.getReference() / mcp.getMaxValue();
// double voltage1 = adcdata1 * mcp.getReference() / mcp.getMaxValue();
double voltage1 = adcdata1 * mcp.getReference() / mcp.getMaxValue();

// print out the value you read:
Serial.print("voltage0: ");
Serial.println(voltage0, 10);
// Serial.print("voltage1: ");
// Serial.println(voltage1, 10);
Serial.print("voltage1: ");
Serial.println(voltage1, 10);
}
}
1 change: 1 addition & 0 deletions examples/analogRead_Scan/analogRead_Scan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void setup() {
;
}
mcp.enableScanChannel(MCP_CH0);
mcp.enableScanChannel(MCP_CH1);
}

// the loop routine runs over and over again forever:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
ReadAnalogVoltage
Reads an analog input off channel0, converts it to voltage, and prints the
result to the Serial Monitor. Attach the center pin of a potentiometer to pin
A0, and the outside pins to +3V3 and ground.
*/

#include "MCP3x6x.h"

#if defined ARDUINO_AVR_PROMICRO8
MCP3561 mcp(2, 3, 10);
#elif defined ARDUINO_GRAND_CENTRAL_M4
SPIClass mySPI = SPIClass(&sercom5, 125, 126, 99, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2);
MCP3561 mcp(84, 81, 98, &mySPI);
#elif defined ADAFRUIT_METRO_M0_EXPRESS
SPIClass mySPI(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
MCP3561 mcp(8, 7, 10, &mySPI, 11, 12, 13);
#elif defined ARDUINO_ARCH_ESP8266
MCP3561 mcp(D1, D2, SS);
// #elif
// todo: might need further cases, didn't check for all boards
#else
MCP3561 mcp;
#endif

void mcp_wrapper() { mcp.IRQ_handler(); }

void setup() {
Serial.begin(115200);
while (!Serial)
;
Serial.println(__FILE__);

if (!mcp.begin()) {
Serial.println("failed to initialize MCP");
while (1)
;
}
mcp.enableScanChannel(MCP_DIFFA);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on default analog channel:
int32_t adcdata = mcp.analogRead(MCP_DIFFA);

// Convert the analog reading
double voltage = adcdata * mcp.getReference() / mcp.getMaxValue();

// print out the value you read:
Serial.print("voltage: ");
Serial.println(voltage, 10);
// pause program for one second
delay(1000);
}

0 comments on commit 9d81802

Please sign in to comment.