## Charge and discharge of a capacitor with PLX-DAQ I propose a new measurement experiment using Arduino, working as DAQ (data acquisition instrument). I proceed as described in the articles Arduino and Excel with PLX-DAQ and Voltage divider measurements with PLX-DAQ: I mount my circuit on breadboard powered by the Arduino board at 5V. I propose to analyze the charge and discharge of a capacitor and collect data in a Excel spreadsheet.
In this lab test, I use the following devices: 1 capacitor 3300µF (electrolytic), 1 resistor 1kΩ,1 switch, 5V Arduino supply.

I write the Arduino sketch reported below.

#define sensorPin A0 // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor 0-1023
float sensorVoltage = 0; // variable to store the voltage coming from the sensor 0-5V
int cont = 0;

void setup() {
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL,t,COUNTER,V-CONDENSATORE");
}

void loop() {
// read the value from the sensor
// calculate voltage
sensorVoltage = sensorValue*5.0/1023.0;
// send value to USB
Serial.print("DATA,TIME,");
Serial.print(cont++);
Serial.print(",");
Serial.println(sensorVoltage);
// delay 100ms
delay(100);
}

The figure below shows a measurement test with data collection in Excel and a 2-Dline type graph to represent voltage measured on capacitor. ## Voltage divider measurements with PLX-DAQ I propose a new measurement experiment using Arduino, working as DAQ (data acquisition instrument). I proceed as described in the article Arduino and Excel with PLX-DAQ and I mount my circuit on breadboard powered by the Arduino board at 5V. I propose to analyze how the resistive voltage divider evolves. I know that when two (or more) series-mounted resistors are affected by the same voltage, this voltage is divided in direct proportion to their size in Ohms.
I do the practical test by mounting on a breadboard a 100kΩ resistor in series with a 100kOhm potenziometer (or trimmer) bridging its central pin with an its side pin (so its resistance varies from 0÷100kΩ).
I perform voltage measurements on the potenziometer using Arduino, changing slowly its resistance over time and collecting data on an Excel spreadsheet using PLX-DAQ. I write the Arduino sketch reported below. Some explanations:

• I use the A0 pin of Arduino as a probe to measure the voltage: #define sensorPin A0.
• With statement #define resistorValue 100 I insert the correct resistor value in kOhm. Knowing that the resistance measurement of a resistor is affected by a tolerance and it deviates from its nominal value indicated with the color code, it would be better to enter its resistance value measured with an ohmmeter.
• To store the voltage coming from the potenziometer I define the variable sensorVoltage.
• After I calculate the voltage that falls on the resistor using the formula: 5-sensorVoltage, and the potenziometer Ohms with formula: sensorVoltage/((5-sensorVoltage)/resistorValue.
• With delay(500) I insert 500ms delay between one measurement and the other so the PLX-DAQ-v2.11.xlsm spreadsheet does not crash Excel.

`#define sensorPin A0       // select the input pin for the potentiometer`
`#define resistorValue 100  // resistor in kohm`
`int sensorValue = 0;       // variable to store the value coming from the sensor 0-1023`
`float sensorVoltage = 0;  // variable to store the voltage coming from the sensor 0-5V`
`int cont = 0;`

`void setup() {`
`  Serial.begin(9600);`
`  //Serial.println("CLEARDATA");`
`  Serial.println("LABEL,t,NUMBER,R-RESISTOR,R-TRIMMER,V-RESISTOR,V-TRIMMER");`
`}`

`void loop() {`
`  // read the value from the sensor`
`  sensorValue = analogRead(sensorPin);`
`  // calculate voltage`
`  sensorVoltage = sensorValue*5.0/1023.0;`
`  // send value to USB`
`  Serial.print("DATA,TIME,");`
`  Serial.print(cont++);`
`  Serial.print(",");`
`  Serial.print(resistorValue);`
`  Serial.print(",");`
`  Serial.print(sensorVoltage/((5-sensorVoltage)/resistorValue));`
`  Serial.print(",");`
`  Serial.print(5-sensorVoltage); `
`  Serial.print(",");`
`  Serial.println(sensorVoltage);`
`  // delay 500ms`
`  delay(500);`
`}`

The figure below shows a measurement test with data collection in Excel. ## Arduino and Excel with PLX-DAQ We know that Arduino allows to acquire data in the analog input. We can use Excel to store data in a sheet and display it in a graph using an application available on the network called PLX-DAQ (Parallax Data Acquisition), but this software doesn't work under Windows 10 and is no longer supported. So we can found a new version of PLX-DAQ re-written by NetDevil, an Arduino forum's member, to be able to be run on modern systems.

We want to measure the voltage variations from a trimmer. We take a device of any ohmic value and connect its two external pins respectively to 5V and GND pins supplied by Arduino. We pick up the voltage signal offered by the central pin, which varies according to the resistive divider that is formed while we turn its knob.
To collect data from our experiment, we can open the PLX-DAQ-v2.11.xlsm worksheet which contains a macro that allows us to save the data from the USB in Excel. To do this, we need to open PLX DAQ clicking on the respectively button and in the popup that the software opens we choose the USB Port to which Arduino is connected. Before clicking on the Connect button, we have to open Arduino IDE and use the sketch that is reported below, or use that is provided with PLX-DAQ software distribution.

`#define sensorPin A0 // select the input pin for the potentiometer`
`int sensorValue = 0; // variable to store the value coming from the sensor 0-1023`
`float sensorVoltage = 0; // variable to store the voltage coming from the sensor 0-5V`

`void setup() {`
`  Serial.begin(9600);`
`  Serial.println("CLEARDATA");`
`  Serial.println("LABEL,t,A0");`
`}`

`void loop() {`
`  // read the value from the sensor`
`  sensorValue = analogRead(sensorPin);`
`  // calculate voltage`
`  sensorVoltage = sensorValue*5.0/1023.0;`
`  // send value to USB`
`  Serial.print("DATA,TIME,");`
`  Serial.println(sensorVoltage);`
`  // delay 100ms`
`  delay(100);`
`}` Let's load this sketch in Arduino, which will send data read from the analog port A0 on the USB, associating them with the instant of acquisition time. We have programmed the Serial.print instructions according to the modality proposed by PLX-DAQ (see the reactive help for more details).
Arduino transforms all the signals that it receives on analogue pins into levels between 0 and 1023, so it is our task to enter in the sketch the calculations necessary to return the correct interpretation to the numerical values ​​obtained. In this case the range 0÷1023 represents the voltages between 0÷5V, so we insert the instruction: sensorVoltage = sensorValue*5.0/1023.0

Before activating PLX-DAQ, we select column B and we assign a 2-Dline type graph to it. In this way, in addition to the data collection, we can see the temporary trend of the signal on the graph.
All versions of PLX-DAQ work good with Excel 2016. ## How to acquire orientation from CPMS03 reading PWM signal with Arduino

Today I try to acquire orientation from CPMS03 compass reading PWM signal with Arduino ATmega2560 in a simple way. I start by saying that the best way to read this sensor is to use the I2C bus connection and the Arduino wire.h library functions. We can find many document in Internet about this way to use CPMS03 compass. But during the construction of our soccer player robots to compete in the RoboCup Junior light, we found an incompatibility between this sensor and the motor shield Adafruit v2.3 that manages its 4 DC motors, because probably both use the same pins SDA and SCL to communicate with Arduino. Because of this, the values ​​provided by the compass are not correct. But the compass is very important for the robot to keep in memory the direction of the goal!!!
So I choose to acquire orientation from CPMS03 compass reading PWM signal provided by its pin 4 and reading by Arduino pulseIn() function. The pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. So returns the length of the pulse in microseconds.
The PWM connection between CPMS03 compass and ATmega2560 is more simple than the I2C bus connection, as you can see in the next photo. In the schematic I connect CMPS03 pin 4 to ATmega2560 digital pin 15, CMPS03 pin 1 to 5V and CMPS03 pin 9 to GND. If you use Auduino Uno, you can do the same connection and use the same sketches I propose, but change digital pin to another number (for example pin 3 instead of pin 15). So I write this simple sketch in whitch values read from compass are printed on Arduino IDE serial monitor:

`// The sketch acquires CMPS03 using pulseIn Function`
`#define PWM_PIN  15`
` `
`unsigned int pwm_value;`
` `
`void setup() {`
`  pinMode(PWM_PIN, INPUT);`
`  Serial.begin(9600);`
`}`
` `
`void loop() {`
`  pwm_value = pulseIn(PWM_PIN, HIGH);`
`  Serial.println(pwm_value);`
`}`

Next, I create a simple sketch to calibrate the range of values ​​read with pulseIn() from the PWM signal of the compass, to solve the problem of orientation calibration, so I can determine the value that the compass assigns north and the  value provided after one complete revolution:

`/* CMPS03 with pulseIn Function `
` * CMPS03 pin 4 is connected to ATmega2560 digital pin 15 `
` * CMPS03 pin 1 to 5V and pin 9 to GND`
` */`
`#define PWM_PIN  15       `

`/* pulseIn returns a max value that exceded the Arduino `
`  max value of an integer = 32767 so we need to use an `
`  unsigned int */`
`unsigned int pwm_value, pwm_value_max, pwm_value_min;`
` `
`void setup() {`
`  pinMode(PWM_PIN, INPUT);`
`  Serial.begin(9600);`
`  pwm_value_max = pulseIn(PWM_PIN, HIGH);`
`  pwm_value_min = pwm_value_max;`
`}`
` `
`void loop() {`
`  pwm_value = pulseIn(PWM_PIN, HIGH);`
`  /* Calibrate Compass to find the maximum and the minimum (NORTH).  `
`   */`
`  if (pwm_value > pwm_value_max)`
`    pwm_value_max=pwm_value;  `
`  if (pwm_value < pwm_value_min)`
`    pwm_value_min=pwm_value;  `
`    `
`  Serial.print("min: ");`
`  Serial.print(pwm_value_min);`
`  Serial.print(" value: ");`
`  Serial.print(pwm_value);`
`  Serial.print(" max: ");`
`  Serial.print(pwm_value_max);`
`  `
`  /* I rotated a CMPS03 sensor of mine slowly in a circle, and I measured that the `
`   *  provided values are in range from 1018 (that I assumed NORTH) to 36383`
`   *  and I stimated the cardinal signs:`
`   *  NORTH = 1018`
`   *  WEST = 35365*90/360 = 8841`
`   *  SOUTH = 35365*180/360 = 17682`
`   *  EAST = 35365*270/360 = 26524`
`   *  `
`   */`
` }`

## Using Atmel Studio 7 with Arduino

In these days I choosed to use Atmel Studio 7 IDE for use with Arduino projects. In a next article I will explain, step-by-step, how I set up it. I tryied to import my projects created in Arduino. I imported into Studio 7 as a C++ project these sketches, including any libraries it references. Once imported, I could leverage the full capabilities of Studio 7 to fine-tune and debug my design.