Newbie question
Posted: Tue Aug 16, 2022 12:50 pm
Hi!
This is my first posting on this forum.
I'm not very good at coding and most of the time I just find some code examples and modify it to fit my use.
Currently I'm building a datalogger card with up to 10 analogue channels. This will be used for a light measurement with four PV panels from LED garden lights.
The unit I'm trying to get working is most likely a STM32F103C6 or a fake STM32F103C8 because this is the only configuration I get working in Arduino.
I have managed to get this up and running with a serial port adapter (FTDI)
The issue is that no matter what I do the native USB will not work and I'm "loosing" two analog inputs PA8 and PA9.
Can anybody direct me in the correct direction to get the USB working?
This is my first posting on this forum.
I'm not very good at coding and most of the time I just find some code examples and modify it to fit my use.
Currently I'm building a datalogger card with up to 10 analogue channels. This will be used for a light measurement with four PV panels from LED garden lights.
The unit I'm trying to get working is most likely a STM32F103C6 or a fake STM32F103C8 because this is the only configuration I get working in Arduino.
I have managed to get this up and running with a serial port adapter (FTDI)
The issue is that no matter what I do the native USB will not work and I'm "loosing" two analog inputs PA8 and PA9.
Can anybody direct me in the correct direction to get the USB working?
Code: Select all
/*
--------------------------------------------------------------
Program: sw_voltmeter_4ch
Description: 4 channel software voltmeter that displays
voltage readings in a Processing application
running on a computer.
Hardware: Arduino Uno with voltage dividers on A2 to A5.
Software: Developed using Arduino 1.0.5 software
Should be compatible with Arduino 1.0 +
voltmeter_4ch Processing software runs on PC
Date: 28 May 2013
Author: W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/
// number of analog samples to take per reading, per channel
#define NUM_SAMPLES 20
// voltage divider calibration values
#define DIV_1 11.00000000
#define DIV_2 11.00000000
#define DIV_3 11.00000000
#define DIV_4 11.00000000
#define DIV_5 11.00000000
#define DIV_6 11.00000000
#define DIV_7 11.00000000
#define DIV_8 11.00000000
#define DIV_9 11.00000000
#define DIV_10 11.00000000
// definition of number of channels
#define CH 8
// ADC reference voltage / calibration value
#define V_REF 3.390
int sum[CH] = {0}; // sums of samples taken
unsigned char sample_count = 0; // current sample number
float voltage[CH] = {0.0}; // calculated voltages
char l_cnt = 0; // used in 'for' loops
void setup()
{
Serial.begin(115200);
}
void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES) {
// sample each channel PA0 to PA9
for (l_cnt = 0; l_cnt < CH; l_cnt++) {
sum[l_cnt] += analogRead(PA0 + l_cnt);
}
sample_count++;
delay(10);
}
// calculate the voltage for each channel
for (l_cnt = 0; l_cnt < CH; l_cnt++) {
voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 4096.0;
}
// each voltage is multiplied by the resistor network
// division factor to calculate the actual voltage
voltage[0] = voltage[0] * DIV_1;
voltage[1] = voltage[1] * DIV_2;
voltage[2] = voltage[2] * DIV_3;
voltage[3] = voltage[3] * DIV_4;
voltage[4] = voltage[4] * DIV_5;
voltage[5] = voltage[5] * DIV_6;
voltage[6] = voltage[6] * DIV_7;
voltage[7] = voltage[7] * DIV_8;
// voltage[8] = voltage[8] * DIV_9;
// voltage[9] = voltage[9] * DIV_10;
// send voltages to Processing application via serial port / USB
// voltage CH-0 (pin PA0)
Serial.print(voltage[0], 3);
Serial.print(",");
// voltage CH-1 (pin PA1)
// Serial.print("B");
Serial.print(voltage[1], 3);
Serial.print(",");
// voltage CH-2 (pin PA2)
Serial.print(voltage[2], 3);
Serial.print(",");
// voltage CH-3 (pin PA3)
Serial.print(voltage[3], 3);
Serial.print(",");
// voltage CH-4 (pin PA4)
Serial.print(voltage[4], 3);
Serial.print(",");
// voltage CH-5 (pin PA5)
Serial.print(voltage[5], 3);
Serial.print(",");
// voltage CH-6 (pin PA6)
Serial.print(voltage[6], 3);
Serial.print(",");
// voltage CH-7 (pin PA7)
Serial.print(voltage[7], 3);
// Serial.print(",");
/*
// voltage CH-8 (pin PA8)
Serial.print(voltage[8], 3);
Serial.print(",");
// voltage CH-9 (pin PA9)
Serial.print(voltage[9], 3);
*/
Serial.println(",");
delay(10);
// reset count and sums
sample_count = 0;
for (l_cnt = 0; l_cnt < CH; l_cnt++) {
sum[l_cnt] = 0;
}
}