Articles Hierarchy

Articles Home » RPI » revive PMS3

revive PMS3

summary:
intro
newest update
back to the basics


intro
with a new RPI2B board and the system optional WHEEZY or JESSIE ( as 2 SD cards ) i want work again.

i had a PMS3 project: Poor Man Scope with 3 Channel,
it is working on a variety of hardware,
-- sampling: arduino UNO, DUE or MAX32
-- visualization: PC or RPI ( HDMI or headless via PC )
-- software: processing or python ( for PC and RPI )
my last BLOG about scope was here and here and here and here and here and here and here and also some old versions at download area ( or just as link to zip file from inside the blog).

here in my BLOG i have that so called CATEGORIES: "arduino", raspberry pi", and even "processing", and also in my entry page "news" WORK BLOG i have 2 sections: "arduino" and " raspberry pi". all that structure not makes sense any more. poorly this old CMS php-fusion 7.2.7 does not support tags. UPS there is a addon i have to test

and so my documentation and software / downloads about that also very confusing, because historically grown.
but that it is what it is about, with the new faster RPI2B i could test processing again for visualization, even on the sampler hardware side no news.

MAX32
as i tested MAX32 , but it is a 3v3 board so needs a voltage divider at the Ains to be used for the 5V world or even bigger voltages ( also DUE board).
and it even needs a different USB cable,
also it needs a different ( modified arduino 0023 ) IDE, but now also for raspberry pi available!
on PC from here download/update with "mpide-0023-windows-20140821.zip" 220MB
upload project: PMS33 (MAXcopy) ok
in line chart mode test: one channel 513kHz, 3 channel 65kHz

Arduino Boards
UNO
here i have the IDE 1.6.5 nightly called "1.6.6 hourly build" from here
upload project PMS33 (UNOcopy see //#define usePROCESSING ) ok as "3 channel line chart" on UNO
no ram for 3 channel 360 samples..to processing scope, but 38 samples for one page line chart good.

you see the 38 lines plus one info line in IDE monitor,
with [+] or [-] can adjust sample rate from 1 channel 35kHz , 3 channel 14kHz .. 24Hz,
and in NO BATCH mode ( line by line analog read and print mode ) down to 30sec sample rate.
above use 1.3kHz ( 38 samples in 28msec batch ) and a open wire at Ain0 touch by hand as antenna for stray 50Hz. you see 26 samples is one sinus, 1315HZ/26=50Hz

when i made that PMS3 code i learned that UNO is to small for the 360samples / 3 channel int array
so i use the "no use processing" thinking means only show 38samples / 3 channel int array for line chart.
implicit i wanted to say: if you use a UNO and the processing "scope" visualization, better use PMS2 only.
now with this release ( PMS34 ) i think i could make a automatic compiler switch to solve this.

DUE
first i had to dismantle my DUE process control system, then
download IDE 1.6.5 r2 (146MB) for test with DUE ( 1.6.5 nightly has no DUE )
again not see DUE board, use BOARD MANAGER, load arduino SAM board ( slow downloading of 85MB more )
upload PMS33due
first using line chart ( //#define usePROCESSING ) again and see 76kHz 3 channel and
655kHz 1 channel ( but then can not change sample rate / screen freeze at next operation )
have to check on update reg. "STIMMER", anyhow close/open terminal resets DUE
but that would make DUE the fastest board.



all 3 boards and software IDEs parallel.
the 3 code projects are ( should be ) same besides some compiler switches "//"
and the MPIDE *.pde naming requirement

as i already make small changes make it a PMS34 ( 3 channel, revision 4 )

Processing
update onWin7 PC: from here i download/update "processing-2.2.1-windows32.zip" 115 MB
load PMS33 / make PMS34 / run. As MAX32 (COM10) and Arduino Due (COM12) running
the "Serial.list()[1]" connected me to MAX32. Now i want to show you a nice picture so get one more board ( Arduino MICRO PRO ) to make me a signal



here i move from PC to RPI2B

but first install on RPI2B WHEEZY the new processing:
i last time use processing-2.1-linux32 and did not get the serial interface running, now i follow here to use newer version, still the actual would be this
try the newer version first:
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install oracle-java7-jdk 70MB
sudo update-alternatives --config java 0 auto jdk8, 1 manual jdk7, 2 manual jdk 8: i select 1???
wget http://download.processing.org/processing-2.2.1-linux32.tgz 98MB
tar xvzf processing-2.2.1-linux32.tgz
rm -rf ~/processing-2.2.1/java
ln -s /usr/lib/jvm/jdk-7-oracle-armhf ~/processing-2.2.1/java
wget https://java-simple-serial-connector.googlecode.com/files/jSSC-2.6.0-Release.zip 276kB
unzip jSSC-2.6.0-Release.zip
mv jSSC-2.6.0-Release/jssc.jar ~/processing-2.2.1/modes/java/libraries/serial/library/
(remove the jSSC folder: rm -r jSSC-2.6.0-Release )
runtest, no serial ...

now as long processing 2xx use JDK7 and not JDK8 hardfloat the improvement could be only by the RPI2B speed. with processing 3 all will be better?? update here
try to run the project but can not find its libraries??
my processing preferences sketchbook points to /home/pi/sketchbook/processing/
and there in /libraries/ i put: Arduino.jar, arduinoscope.jar, controlP5.jar
prior it worked ( and still under windows with same 2.2.1 version ) with that libraries inside a /code/ subdir with the project.
hmm, a version problem? see here
processing2-arduino.zip
controlP5-2.0.4.zip
arduinoscope-master.zip
still error cc.arduino not found, that is about the linux name problem:
rename the "new" /home/pi/yoursketchbook/libraries/arduino/library/Arduino.jar to arduino.jar, now load ok



for arduino have the IDE 1.6.5 for raspberry MAX32 MPIDE need
wget https://chipkit.s3.amazonaws.com/builds/mpide-0023-raspberrypi-20140821.tgz 242MB
tar xvzf /home/pi/mpide-0023-raspberrypi-20140821.tgz
yes better would be under /usr/share/ where also arduino IDE is.

here even a 1.5.0 version available??
anyhow now follow this:
sudo apt-get install gcc-avr ( should be there for arduino already exists_OK )
sudo apt-get install librxtx-java i remember, that's the bad one exists_OK
Add the following lines to your .profile: ... // can also be part of start like with arduino
see sudo cat /usr/bin/arduino
Disable console on serial port on RPi? // should not be needed
hard link named /dev/ttyS0 to /dev/ttyAMA0 and start by ./mpide // could be done like arduino start
here is what i try:
cd /usr/share/applications/
sudo cp arduino.desktop mpide.desktop
sudo nano mpide.desktop
name MPIDE0023 , exec mpide0023
cd /usr/bin/
sudo cp arduino mpide0023
sudo nano mpide0023
...
that code you will find in download pack later
so, MPIDE start via desktop menu,
but intro picture missing, version info missing, port grey,
when i start ./mpide manually add see a warning:
RXTX Version mismatch jar: 2.1.-7, lib: 2.2pre2
just to be sure i do the 3 additional hevangel things
3. sudo ln -s /dev/ttyUSB0 /dev/ttyACM0
4. sudo usermod -a -G dialout pi
5. sudo usermod -a -G tty pi
anyhow copy in my PMS34 sketch from MPIDE of PC and open in RPI MPIDE
connect MAX32
port see /dev/ttyUSB0 select
verify, upload, monitor OK


run PMS3 on RPI2B / wheezy / processing 2.2.1 / by MAX32 PMS3 scope and a "Arduino micro pro" testsignal

after change port in processing sketch list[2] it runs. but it seems to be an old code, need the update with the zoom buttons / copy PMS43 from PC OK
and for channel 2 and 3 have signal problem, even i have no idea what could be different now from the last PC setup? USB HUB? ( a additional GND wire MAX32 Arduino MICRO PRO not helped )
but download SAME CODE via MPIDE from PC to MAX32 back to RPI



now after copy new MPIDE code from PC to RPI again and copy it to arduino sketchbook
at compiler ( verify) start the .pde are renamed to .ino ( not by IDE 1.0.1 ??)
running Arduino 1.6.5 on RPI i need again first use board manager to be able to use DUE
but compile give error

test the UNO with the new compiler switch ( back to 2 channel ) worked in chart line and processing

but could not close scope window, so try again that prepared switch
#define useRPI what slows serial com down for RPI. ( same baud rate but delays in sending // that needs tuning) use
//#define useRPI
anyhow UNO 2 channel trick works now


detailed system layout:



i have to get the PYTHON tools ( as processing replacement ) also running again, see here
arduino_stream_PMS3.py
and its autostart
PMS3scope_v3.py
first on PC

starting the arduino_stream_PMS3.py from python IDE 2.7.6
and adjust COM10, i see warnings about "TOO SHORT LINE" ( seems to be between info line and first data set?? need check arduino code )
and a batch CSV write of 10 files ( 1 info line , 360 data lines) to C/temp ( about every 1.4sec )
starting it with double click execute it directly in python.exe and start the scope by python IDE,


now i want to make PC and RPI version same by detecting OS.
here after copy to RPI the stream run by python2 IDE for diagnostic

but you can also just start it from terminal by
python /home/pi/sketchbook/python/arduino_stream_PMS34.py
after do the auto start thing on the service ( see file and info )

After you have the matplot lib installed
sudo apt-get install python-matplotlib
you can start the scope from terminal
python /home/pi/sketchbook/python/PMS3scope_v34.py
or by the new desktop icon.

what i see after first start was that i get every 1.4sec a new dataset from arduino (due)
to a csv file in RAM_DISK, but the scope shows [conti] mode, only every 2nd,
? because of this? timer = fig.canvas.new_timer(interval=2000) # 2 sec
so, with the new and faster RPI2 have to check on all timing on arduino and RPI side.
ok, displayupdate 1sec (1000) ok, read every file now.

somewhere on the way to here i lost my arduino micro pro
when i connect it to any computer i not see a USB device ( as it was a leonardo i should see even 2 )
if i burn it by breadboard wiring or if it is possible that i killed it by a broken upload ??


for operation pls find 2 desktop files:
one for stop/start/restart/ or check the service
one for starting the scope.
code or load it from RPI with
wget http://kll.engineering-news.org/kllfusion01/downloads/PMS34.tar.xz


for the service i work on the operation from desktop,
because if you make it autostart / at boot /
but later need to change the arduino ( arduino IDE .. ) the port is blocked by the service,
you need to stop it first, that operation is possible by click on a icon.
for a little framework only about that autostart and operation pls see here


i work from remote ( headless / remote desktop program (xrdp installed))
and i see a problem that the RPI2 desktop sometimes can not be operated,
spec. the scope window can not be closed. ( but screen not frozen / see data update... )
but on headerline "program" right click "close window" works
but when i close and reopen the RDP window, the operation (closing the windows ) is possible again.
could be a problem with the PC RDP.


long time has gone by that i used this, but now i moved from
"desktop application" to "web service", means still a python service has to catch the arduino (batch) stream to files at RPI RAM DISK, but the whole visualization and operation is now via a web page, what is part of a bigger project: python flask web server with blog cms, GPIO usage and 3 ways to use a arduino type device on usb cable as extended I/O.

PMS again ( 5/2018 )

what is about PMS inside myBlog, a python/flask/webserver/blogCMS/


newest update
update 07/2019
lately, work with processing ( current rev. 3.5.3 ) and want test that old show again.
+ + download from here and a updated version ( arduino only ) from here
to Raspberry Pi still on
DEBIAN stretch / Linux version 4.19.42-v7+ / on Raspberry Pi 3 Model B Plus Rev 1.3
update:
DEBIAN buster / Linux version 4.19.58-v7+ / on Raspberry Pi 3 Model B Plus Rev 1.3

and using Arduino IDE 1.8.10 Hourly Build 2019/05/21

try the processing 2 sketch, loaded cp5 library,
but the also used library arduino scope
is not usable in processing 3xx any more, so i might need a complete remake,
and try it without any library,
* using my own " registered Button array class "
* and a one scope 3 color beam easy draw points on rectangle background
well, 3 beam in one scope might reduce visibility,
but the new size ( 360 * 512 px ) allows a 1024/2 visualization
i think that means increased visible scope resolution.



now even i call that PMS3 it can be only a 2 beam scope if i use
arduino UNO/Leonardo
because there is not enough RAM for a int[360][3] storage array.
AND for the high-speed sampling anyhow only beam0 is measured/stored.
but i will try again to wring a few bytes out of the code ( variable space )
and test also if a int[2xxx][3] would work?
without the need to change all the rest ( data transport / processing visualization )
shorter beams are acceptable ( 260 instead 360 in one line )
going down to 8bit 256 steps byte storage array is not worth it.

+ + int[260][3] instead int[360,2]
- - so the x axis still has 360 pix and only data for 260
- - and also the min evaluation uses the 260 .. 359 array vals what are 0
- - the ( per beam ) indicated Apin y[V] takes the last array value so also 0
// possibly that all was not the best idea / would need lots of new code to fix //
+ + and also play Win 10 PC and Arduino UNO / instead RPI and Arduino Leonardo
+ + and finished the 3 beam / move / zoom / button menu with RESET

for this test i had to touch the arduino code for the first time in years
( and with this also loose the context to the MASTER CODE as .PDE version for the MAX board )



when i connect UNO and Leonardo ( needed a new cable ) and DUE ok.
new idea is to use the DUE as a signal generator ( DAC0 / DAC1 ) with a "analog ramp" signal
-a- PMS35 on UNO
-b- signal from DUE ( analogWrite 0 .. 1024 )
-c- GND - GND / A0 - DAC0 / A1 - DAC2 / wires

so: what we see here?
UNO tells he measure with 608Hz a array of 360 values,
so the scope screen should be 0.592 sec
we see 6.3 red ramps or 1.4 blue ramps
DUE tells a red ramp is 378ms, a blue ramp is 1891ms
( millis calc and serial print // also confirmed by the arduino monitor timestamp )
so the scope screen should be 2.3 or 2.6 sec ( very much different from scope info )
also the ramp V is 0.56V to 2.77V ( instead 0 .. 3.3V )
so the ramp range is a known DUE DAC limitation ( 0.55 to 2.75V ).

i really need a calibrated signal generator to check the scope.

but first i change for visibility from POINT to LINE ( and strokeWeight(2) )
and show also a PULS signal from DUE to verify 0 .. 3V3 ( yes V= 5V * 683 / 1024 )
and with using the millis info from arduino DUE about the pulses that fits with PMS,
still millis about ramp is OFF.



here now the look same signal other speed setting ( on a UNO ):
the used puls has about 2ms ( on or off time )
fastest: 39kHz ( sample A0 only with special arduino function )


with 24kHz and 2 beam


and a slow setting to see the full ramp 3kHz




i had the feeling that the frequency numbers not fit for the one channel,
so i decided to check/work on the arduino code again
AND i found a ERROR in the delay timer logic!
also i changed from WHILE to FOR loop and
even there are so many options ( #compiler options for hardware and logic if )
i try to change that, so i not need to do many IF inside the FOR loop over the ARRAY.
( with the ugly consequence that i now have many different FOR loops in the code )
BUT its all faster now.
> only test with UNO ( and WIN 10 / processing 3.5.3 )
PMS3_arduino/Batchsampleold ( original 2013 see max 35kHz but ?new IDE? now)
/1/2 channel / 14ms / 24070Hz
/0/1 channel / 9ms / 39060Hz
change while to for loop
change Batchsample // line 34 delaytimer logic ( and test with UNO )
/1/2 channel / 12ms / 28450Hz
/0/1 channel / 6ms / 52470Hz
change make many for loops but reduce if... inside if only one channel reading
/1/2 channel / 12ms / 28750Hz
/0/1 channel / 6ms / 55350Hz || could be very big speed up






ok, i will never have / buy calibrated signal hardware, but i read that post at the processing forum
about sound sampling here and now have the idea to install a microphone to A0?
while for signal generation can use any PC/RPI Audacity / generate tone / sawtooth _ Hz _ length /

and play it.
so if that hardware works, and i can adjust any signal HZ in a Audacity generator and i see that signal in PMS and it fits into the PMS screen ( last i used 360 samples array / 2 beam UNO )
i would trust my own work. ( still open )


same time i have a new idea change the layout little bit
use 256 samples ( even on UNO 3 beams possible )
zoom the signal ( 1024 down to 512 pix hight)*( 256 samples zoom up to 512 pix wide)
also changed the frequency indication,
now "xxxHz yy ms/ 256" (samples) switch auto yyms or YYYYYus


up to now there was still a function hidden in the keyboard menu i disabled and make 2 new buttons
the beam 1 and beam 2 can have a input select like
beam 1 start A1 [next] A2 A3 A4 A5 A0 A1 same beam 2 but start A2
beam 0 is fix on A0




here the PoorManScope 3 rev 5 ( arduino / processing 3.5.3)
PMS_3v5.3.1


with 256 sample array i would have also a good data bases to do a FFT , like i did in the early versions already.
a spare button in rev 3.5.3.1 is prepared already.


back to the basics
above thing is a 10 years grown project, after latest rewrite for processing in good shape,
but unreadable, and even for me difficult to maintain.

so if a beginner with arduino / processing want do the first steps ( ardu scope.. )
and he ends up here? LOST IN TRANSLATION


so we start like in a 3 step lesson with the basics again:
-A- minimal communication:
* we want read with arduino 5V analog signals on A0 and A1
* print to serial USB
* catch that with a processing program and print to console
arduinovoid setup() {
Serial.begin(9600);
}

void loop() {
Serial.print( analogRead(0) ); // A0
Serial.print(",");
Serial.print( analogRead(1) ); // A1
Serial.println(",");
delay(1000); // every second
}


/* if A0 at 5V see on arduino monitor
1023,868,
1023,867,
1023,866,
1023,865,
1023,866,
1023,866,
1023,867,

*/

processingimport processing.serial.*;

Serial myPort;
String data;

void setup_serial() { // USB arduino..
printArray(Serial.list());
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
myPort.clear();
myPort.bufferUntil('\n');
println("try connect to "+portName);
}

void serialEvent(Serial p) { // handle serial data
data = trim(p.readStringUntil('\n'));
if (data != null) {
println(data); // print every GOOD line
}
}

void setup() {
size(640, 360);
setup_serial();
}

void draw(){}

/*

[0] "COM1"
[1] "COM7"
try connect to COM7
1023,869,
1023,833,
1023,862,
1023,866,
1023,866,

*/

-B- show the arduino lines on Canvas instead at console
* need a String array to remember
processing// rev 0.1 add a list of records

import processing.serial.*;

Serial myPort;
String data; // latest arduino line
// rev
int[] datos; // as array of integers
StringList list; // stored lines
int listlong = 18; // many

int w= 640, h = 360; // canvas settings

void setup_serial() { // USB arduino..
printArray(Serial.list());
String portName = Serial.list()[1]; // adjust 0.. x port
myPort = new Serial(this, portName, 9600);
myPort.clear();
myPort.bufferUntil('\n');
println("try connect to "+portName);
}

void serialEvent(Serial p) { // handle serial data
data = trim(p.readStringUntil('\n'));
if (data != null) {
//println(data); // print every GOOD line
datos = int( split(data, ",") ); // create int array (unused example )
list.append( data ); // OR store line as String list
if ( list.size() >= listlong ) list.remove(0); // erase the oldest? // for ( int i = 0; i }
}

void settings() {
size(w, h);
}

void setup() {
list = new StringList();
setup_serial();
}

void draw() {
background(0, 0, 80);
for ( int i = 0; i < list.size(); i++ ) text( list.get(i), 10, 20+i*20 ); // running list of arduino lines
}

-C- add a little PLOT area for that recorded ( string ) data lines
processing// rev 0.1 add a list of records
// rev 0.2 add a plot from string records array

import processing.serial.*;

Serial myPort;
String data; // latest arduino line
// rev
int[] datos; // as array of integers
StringList list; // stored lines
int listlong = 18; // many

int w= 640, h = 360; // canvas settings

// rev plot
int a=100, d = 5; // scope background area rectangle
int[] datos1, datos2; // as array of integers to make 2 lines
float range = 0.3, basex = 120, basey = h-30; // scope area
float step = ( w-basex-20-d )/ ( listlong-1 ); // line step calc of array length

void setup_serial() { // USB arduino..
printArray(Serial.list());
String portName = Serial.list()[1]; // adjust 0.. x port
myPort = new Serial(this, portName, 9600);
myPort.clear();
myPort.bufferUntil('\n');
println("try connect to "+portName);
}

void serialEvent(Serial p) { // handle serial data
data = trim(p.readStringUntil('\n'));
if (data != null) {
//println(data); // print every GOOD line
datos = int( split(data, ",") ); // create int array (unused example )
list.append( data ); // OR store line as String list
if ( list.size() >= listlong ) list.remove(0); // erase the oldest? // for ( int i = 0; i }
}

void settings() {
size(w, h);
}

void setup() {
list = new StringList();
setup_serial();
}

void draw() {
background(0, 0, 80);
for ( int i = 0; i < list.size(); i++ ) text( list.get(i), 10, 20+i*20 ); // running list of arduino lines
plot();
}

void plot() {
push();
fill(100);
rect(a, d, width-a-d, height-2*d);
for ( int i = 0; i < list.size(); i++ ) {
datos1 = int( split(list.get(i), ",") );
if ( i < list.size() -1 )
datos2 = int( split(list.get(i+1), ",") );
else
datos2 = datos1;
stroke(0, 200, 0);
line(basex+i*step, basey-range*datos1[0], basex+(1+i)*step, basey-range*datos2[0]);
stroke(200, 200, 0);
line(basex+i*step, basey-range*datos1[1], basex+(1+i)*step, basey-range*datos2[1]);
}
pop();
}

/*
[0] "COM1"
[1] "COM7"
try connect to COM7
*/




your homework:
-A-
depending on your hardware
* PC
* arduino
* USB cable ( length )
you can speed up the baud rate ( on both sides )
find out at what rate it starts to get bad ?2000000?
-B-
change the delay timer in arduino ( sample rate )
* to send more lines per sec.
* disable println() commands in processing if still active

so what sample rate is possible for this ARDU SCOPE?
* read about the sample theorem and understand that you only can find
frequencies of half of the sample rate

go back and test PMS3 at fastest speed ( one channel (A0))
and compare the sample rate ?
what is the keyword to understand the differences in the two methods.