Articles Hierarchy

Articles Home » Arduino Projects » ARDUINO PROJECT: 3.5D datacollection

ARDUINO PROJECT: 3.5D datacollection

ARDUINO PROJECT: 3.5D datacollection
for a automatic test bench a arduino could measure (Z) the data of 2 sets (N) over 2 parameter (X, Y)

after PROCESSING and CSV file store
and PROCESSING: 3.5D graph and EXCEL tool
the question is where in the real world is a requirement for that 2 plane 3D data set
and visualization.

Now, when i use a arduino for a automated test bench
it could measure a
Z analog input ( A0 ) while change parameter
X dout PWM ( D5 ) and
Y dout PWM ( D6 )
with a optional
N dout ( D7 ) altering the whole test field
( like just switching between a TEST and the REFERENCE DATA ).
in a automatic batch routine.

The test sequence must be fully automated, because its not known
how fast that later should perform,
BATCH timeframe adjustable: 1.3sec .. 4days? LONG vs. millis()?
the data collection must be done to array, and at the end send to terminal OR processing
in a batch form, to create the CSV file we use later in PROCESSING: 3.5D graph

even it would be a dream to have a
X - Y table with positioning like for a CNC machine or a measuring robot
or a chemical batch preparation mixing some stuff and measure pH or ORP or salinity...

i will here use the X , Y outputs in a very simple electrical way,
for long time already i wanted to play with the generation of a real ANALOG OUTPUT signal.
The PWM outputs must charge a RC ( resistor + capacitor ) network to generate a voltage signal
we want to measure here as Z.
The PWM output setpoints will be 0 .. 255 == 0 ..100%
but in steps, representing 0..7 for X and Y.
while this will give us only a very planar field ( of voltage / our reference data )
we need some more action:
with the output N we will switch a LED to discharge above voltage source.

1. approach for the MEASURING FIELD:

but as usual first the software,
i start with the menu default program,
and make the array N,X,Y,Z as integer ( because Z as float not fit into arduino UNO
and a analogRead gives anyhow only 0 .. 1023 )

menu: under (1 BATCH START/STOP )
must first adjust 2 timer,
with space Enter get the default
add there are minimum limits adjusted.
1 Enter, space Enter, space Enter gives:
set a timer setpoint every (default 1000 millis): no number input, use default! 1000
set a settlement delay timer setpoint (default 10 millis): no number input, use default! 10
BATCH start days: 0 time: 0 : 0 : 8
BATCH finished days: 0 time: 0 : 2 : 15

2 * 60 +15 - 8 is about 127 sec
the value list i copy for test directly to the 4D.csv file.
As i measure Ain0 open input its actually a undersampling of 50 Hz sinus noise, looks like:

1 Enter, 1 Enter, space Enter gives the adjusted minimum:
set a timer setpoint every (default 1000 millis):TOO FAST, set to 10
set a settlement delay timer setpoint (default 10 millis): no number input, use default! TOO LONG, set to 8
BATCH start days: 0 time: 1 : 5 : 9
BATCH finished days: 0 time: 1 : 5 : 11

128 measurements at 10millis should be 1.28sec.
but my default time ( no RTC, only internal millis) shows no better resolution.

that timer limits must be verified later, but as the PWM have a basetime from
1millis ( 970Hz for UNO and D5 D6 on timer 0 divisor 64 ) PWM info and here
a settlement time of 8millis would mean 8 PWM cycles "analog" output only.
I understand that the settlement time ( between N and X,Y PWM setpoint output
and taking the measurement ) can be a critical process time.

A different approach would be not to have a delay timer for settlement,
i could set n+1 setpoint directly after each measurement n and with this have a maximum length of possible settling, about the sample time.

just for the signal quality? a wire Ain0 to 3v3 brings data 698 .. 701.
as the USB link not active while measurement ( using 3v3 inside arduino )
its some noise. ( 701-698 /1023 * 5 == 15mV )
a wire Ain0 to GND shows clean 0 over the whole batch.

lets get the breadboard and wires...
while i wired i understand already that there is no power for the LED to light up,
even still it works as a diode, so i changed the 4K7Ω to 470Ω
and got a little red light dimming and blinking according test cycle.

copy the terminal data and show 3.5Dgraph:

and that after the first switch ON!!
On the N=1 plane you see how the voltage dips with the LED connected
( to GND via the N=1 Dout7 = LOW).

So, actually that project could be finished here.

But i want to improve the arduino TEST BENCH software,
-a- want a local PB (to GND) to start the batch (Din 4 with internal pull up )
and use debounce lib.
-b- it should be possible to adjust any manual setpoint for not batch operation.
see new menu point (3)

-c- first i did not make the processing tool what
operates arduino and catch and write CSV file. ( actually the copy paste is too easy )
but i had a fancy idea, i just included in the visualization the complete communication with arduino.
if you ever play with that connection arduino processing you know that there
is no easy way to select USB port.
the new code shows a list of all com ports,
and opens item [1] of that list.
if nothing is connected get that many red error lines, but n.p.
if the number is wrong you must change it manually in the code.

now have add the 3 keyboard commands for
- (1) Arduino run batch
- (2) Arduino send data and processing stores it to a temporary file
( see also arduino serial USB menu, same 1,2 )
the defaults for the measuring batch timer setpoint pls change here in the processing code,
i use sampletime 1000millis, and settling 900millis.

now its recommended to do some filebackup manually,
i did not want to fill up the harddisk, but the temp file has actually a good name for long time storage, 4Dyymmddhhmmss.csv, using the time of the data transport to processing.

- (r) rename temp file to datafile and open, read, and 3.5D graph it.
keys and functions:

here a remark about that 2 steps:
[1] get timer setpoints and starts the batch sampling,
prints already the resulting array at the end of the batch.
[2] just prints the array again

- so for copy paste of the CSV content list you don't need [2]
- on arduino [2] not makes much sense.
if you shut down arduino and start processing, the init of the serial link
resets the arduino, a [2] prints the default list, the measurements are gone.

with that understanding it is clear why in / from processing we must operate
[1] measurement batch
[2] logging ON to temp file, ask for send array data again with 2, logging OFF
[r] delete old 4D.csv!!! rename temp file to 4D.csv. open read graph it.

but you should know that there is the possibility to [1] measure from arduino terminal.
shut it down,
start a other terminal like HTERM, send [2] and get the data, and use the save output to file feature.
because that terminal software does not do a reset of the arduino!!
and the arduino not even echo the '2' , so the outputfile is clean for use as 4D.csv.

i pack the V1.0 code of both projects for you.

in rev 1.01 i included in arduino AND processing the
(3) manual setpoint
(4) conti measurement
where in (4) a further adjustment of setpoints is possible.
using nNxXyY for the 3 parameters down UP ( x,y ramping +- 5of255).

( note: on arduino terminal must use [key][Enter] in processing ONLY [key] )
its a kind of blind operation, but you see the result Z in terminal.
if you lost with the setpoints for X, Y can use [d] for diagnostic ON/OFF,
there you can see the actual setpoint.
Be careful,
in arduino must be the terminal window active and cursor in input field!
in processing must be the GRAPH window active ( but there nothing will change)
but just look diagnostic window for arduino answers.
if the processing or arduino window (EDITOR) is active your key operation will
just end up somewhere in the code. LOL

now for the second arduino job ( together with the 4 resistor, one LED and one capacitor )
to make a analog signal i can not live with the internal volt reading,
i need to see it on a oscilloscope.
- should there be a analog filter for the A0 input?
- now i think that the PWM is loading AND unloading the capacitor?
do i need diodes in the loading path, and only do unloading via capacitor bypass resistor
AND LED circuit?

start with the PoorManScope2 on a old arduino mega 1280
connect Ain0 to Z (= Ain0 UNO ) ( and GND to GND even it is connected via USB )
i must say i am impressed by the signal, never more bad as 0.5V delta.
i used the scope in the highest resolution ( only as one channel with 8400Hz )

| N X Y | N X Y |
| 0 100 100 | 1 100 100 |
| 0 100 50 | 1 100 50 |
| 0 50 50 | 1 50 50 |
| 0 0 50 | 1 0 50 |
| 0 50 0 | 1 50 0 |
| 0 0 0 | 1 0 0 |

when i reduce to 4300Hz sample rate automatically can see 2 channel,
like the PWM Ain1 to D5,or Ain2 to D6 of UNO
but the resolution is too bad, need to beef up the hardware.

use the same PMS2 code, load MP IDE and upload to MAX32 board.
( MAX32 can do 1 channel 530kHz with the ASM code)
adjust 25kHz sample time and see

and now the PWM5 and PWM6 with setpoint 50%, i see they have same start / stop time!

to understand the scaling in detail:
on arduino UNO, MEGA the range is 5V, with 10 divs in PMS2 chart means 0.5V/div ( 2div = 1 V )
as the MAX32 is a 3v3 type it will be 0.33V/div, ( 3div = 1V )
but i need measure a Arduino signal ( PWM about 5V ), so i had to build a voltage divider with
Arduino signal - 10k - MAX32 signal - 10k - GND. With that, 1.5div = 1V.
the signal shows only 2.3V instead the expected 2.5V??
with X and Y at 100% my DVM also reads 2.3V,
at the UNO dout 4.65V and at UNO "5V" only 4.7V, like the MAX32 "5V", It must be the USB
but can not find my UNO powersupply now.
My UNO LOAD? assuming worst case the capacitor as a short, the 470ohm will be 10mA
the 1k 5mA, the PB is N.O. normally open.
insofar is the MAX32 more accurate because it makes from USB "5V" the 3V3, the UNO runs on that USB "5V".

So, now its time for the diodes test:
D5 and D6 are via diodes loading the RC network, but can not unload it.
here the pictures by my new tool, i am too tired to think about it now.

and the final hardware assembly:

with circuit:

ok, back to the question what we did, when we added the loading diodes.
first, they reduce the loading voltage ( 5V ) from the PWM pins by 0.7V.
The plan was that now the "analog voltage" is not discharged by the PWM signal, only loaded.

How to find out about the absolute voltages we get now, its too much data to compare,
would need to check on the datafield
FILE1: without the loading diodes and
FILE2: with the loading diodes.
and then again same for the situation if
N=1: a discharge LED connected
N=0: or not.
would be good to have some tool for that? UPS, we just build one.
what i do now is to mix the Z data of the 2 CSV files in following way:
now N=0 contains the first 64 Z values from FILE1
and N=1 contains the first 64 Z values from FILE2
now N=0 contains the last 64 Z values from FILE1
and N=1 contains the last 64 Z values from FILE2


now we sure that the loading diodes not make much sense, they change a planar voltage field to a curved one, and have a lower voltage in high range, with or without load.

using the linechart tool of PMS2 i was not happy with the
2 channel scope and the b channel switching,
so i used half hour to make PMS3, a 3 channel scope!
( now the voltage divider can be tuned in there too, the indicated volts are correct,
but thats only a raw version,
as the 3rd measurement takes time, the +- dial ( delay time) array must be adjusted new, for MAX32 and for Arduino ) so here just measure with 22kHz.
and the PMS normally comes with the fitting processing scope
so that is some more work until PMS3beta is ready.
MPIDE terminal window:

with (0) = voltage signal, (1) = D5_PWM, (2)=D6_PWM,
TESTBENCH setting N=0, X=75%, Y=50%.
processing with PMS3 scope

( for the new processing needed to update the controlP5 lib
and have issues with the initial talking with PMS3 arduinoMEGA/max32 board for not sending chart lines, only values ?timing?)
but, looks very nice.
as line chart tool i work with a array length of 38 samples
and that fits into UNO even with 3 channel sampling.
but for the processing tool operating it, i switch to 360 array length == width of scope.
and that is possible with UNO only for PMS2, the 3 channel array / 360 records long
not fit into UNO.
( now there is a compiler switch at the beginning for enable / disable processing use on
PMS3 )

here, the TEST BENCH tool on a arduino UNO,
the PMS3 on a MAX32
and its processing scope visualization.

i pack the
data_visualization_4D (V1.01) and
PMS3 (MPIDE ( can be used in Arduino IDE too) / Processing) code of both projects for you.

one of the not so nice things is that the setup try to connect to a arduino board
( COMx) without asking first, connecting to a board should be just a option.
while i want to work on the operation concept, i first want to deal with that link issue.
using processing 2.0.3 and a new controlP5 lib i made the com link selectable.

and use more of that buttons ( to do all you can do by keyboard also now by mouse click )

and now have 3 planes?
yes, from rev 2 there is the option ( in arduino and processing code also in excel tool )
to use 3 level for N.
and just as a example i use in the arduino code D7 as TRI STATE,
N=0, D7=LOW,
N=1, D7=input,
N=2, D7=HIGH
above 3 planes are the result of it, add to 5 resistors and one capacitor.
Vcc - 10k - Z
GND - 10k - Z
D5 - 10k - Z
D6 - 5k - Z
D7 - 2.5K - Z
GND - 10uF - Z
Ain0 - Z
the N=1/ D7 INPUT plane has a different slope as the others, i did not try to calculate that network.

That measuring array now is 192 records long ( 3 * 64 ) using ( byte,byte,byte,int for N,X,Y,Z )
( in arduino there is a compiler switch, in processing a variable )

in rev 2.1 full operational from processing via buttons.
but somewhere on the way i loose the file rename?? it gives now error for deleting the "old" 4D.csv file.
so instead of rename i open and read that just made last file from arduino.
for using that data after restart you need to copy/rename that data file manually to D4.csv.

and now in menu 4 CONTI MEASUREMENT, with the incremental N,X,Y adjustment,
that measuring point is shown in the 3D GRAPH as a big white DOT.

pls find that version at download area.

i have a issue with processing 2.0.3,
because i use in setup: size(wX,wY,P3D) instead of size(wX,wY)
the setup is executed 2 times??? very strange, and to find that line needed digging deep.
but forum helped, my mistake.

pls find next: signal generator