group assignment:
compare as many tool options as possible
author : Kai
To visualize sensitive value from step response sensor I made on week11 using Processing.
Sensor module > Processing
capacitive sensor board by Neil
Sparkfun Tutorial : Connecting Arduino to Processing
I struggled to make processing program to successfully receive the serial that is sent out from sample board.
I found the document from former Fabacademy student Tiago that does exactly the same thing as I wanted to do.
Communicate with capacitive sensor board using serial
(Serial communication relevant part abstracted. Look source for the full code.)
void draw()
{
while (myPort.available() > 0) { // If data is available
byte1 = byte2;
byte2 = byte3;
byte3 = byte4;
byte4 = low;
low = high;
high = myPort.read();
if ((byte1 == 1) & (byte2 == 2) & (byte3 ==
3) & (byte4 == 4)){ // Filter out the framing numbers: 1,2,3,4
value = (256*high + low)/100;
filt = (1-eps)*filt + eps*value;
println("THE VALUE IS " + value); //print to the screen
}
//EXPERIMENT WITH THE VISUALIZATION BELOW
background(322); // Set background to white
int scale = 10;
rect (20,20,value,20);
}
}
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
int sensorData; // Data received from the serial port with 1,2,3,4 framing numbers filtered out
int low=0;
int med=0;
int high=0;
int value=0;
int byte1 = 0;
int byte2 = 0;
int byte3 = 0;
int byte4 = 0;
float filt;
float eps = 0.75;
float s = 0.0;
void setup()
{
size(640, 360, P3D);
noStroke();
colorMode(RGB, 1);
fill(0.4);
println(Serial.list());
myPort = new Serial(this, "/dev/tty.usbserial-FTGNZXMP", 9600);
}
void draw()
{
while (myPort.available() > 0) { // If data is available
byte1 = byte2;
byte2 = byte3;
byte3 = byte4;
byte4 = low;
low = high;
high = myPort.read();
if ((byte1 == 1) & (byte2 == 2) & (byte3 ==
3) & (byte4 == 4)){ // Filter out the framing numbers: 1,2,3,4
value = (256*high + low)/100;
filt = (1-eps)*filt + eps*value;
s = float(value);
/*
s = s -500;
s = s * 8 / 1000;
if(s < 0){
s = -s;
}
*/
s = map(s, 510.0, 550.0, 0.0, 1.0);
if(s < 0){
s = -s;
}
}
}
//EXPERIMENT WITH THE VISUALIZATION BELOW
background(0);
translate(width / 2, height / 2);
// Set the specular color of lights that follow
lightSpecular(1, 1, 1);
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
specular(s, s, s);
sphere(150);
println(s); //print to the screen
}
author : Daisuke
from Tkinter import *
from numpy import log
import serial
WINDOW = 600
def measure(parent,canvas):
mydata = ser.readline()
mydata = mydata.replace('\n','')
mydata = mydata.replace('\r','')
if mydata.isdigit():
mydata=int(mydata)
B = 3750.0
T0 = 298.15
R0 = 10000.0
R1 = 11200.0
try:
rr1 = R1 * mydata / (1024.0 - mydata)
t = 1 / (log(rr1 / R0) / B + (1 / T0))
t= t- 273.15
t=round(t,1)
r=t*5
fred=int(255*t/40)
fblue=int(255-255*t/40) #range0-40degree
color = '#%02x%02x%02x' % (fred, 0,fblue)
fred=int(255/5)
canvas.itemconfigure("text",text=t)
canvas.coords('oval',.5*WINDOW-r,.5*WINDOW-r, .5*WINDOW+r, .5*WINDOW+r)
canvas.itemconfigure('oval', fill=color)
canvas.update()
parent.after_idle(measure,parent,canvas)
except:
print("error")
return
ser = serial.Serial(
port = "/dev/tty.usbserial-AI02RJUC",
baudrate = 4800,
parity = serial.PARITY_NONE,
bytesize = serial.EIGHTBITS,
stopbits = serial.STOPBITS_ONE,
timeout = 1,
xonxoff = 0,
rtscts = 0,
)
root = Tk()
root.title('Temperature (q to exit)')
root.bind('q','exit')
canvas = Canvas(root, width=WINDOW, height=WINDOW, background='white')
canvas.create_text(.5*WINDOW,.05*WINDOW,text="temperature",font=("Helvetica", 24),tags="text",fill="#0000b0")
myc=canvas.create_oval(.5*WINDOW-10,.5*WINDOW-10, .5*WINDOW+10, .5*WINDOW+10, tag="oval",fill="green")
canvas.pack()
root.after(100,measure,root,canvas)
root.mainloop()
author : Jun
I downloaded blynk libraries and included it from arduino IDE. I also have to install Socat prior to controlling a satshakit wi th Blynk over USB.
After that, I ran a script in scripts folder and type a serial port found (depnding on your condition; here example "/dev/tty.usbmodem141221")
KWHRJN:scripts kwhrjn$ sudo sh ./blynk-ser.sh
1 ports found. You can specify port manually using -c option
-n Select serial port [ /dev/tty.usbmodem141221 ]:
/dev/tty.usbmodem141221
Resetting device /dev/tty.usbmodem141221...
[ Press Ctrl+C to exit ]
Connecting: GOPEN:/dev/tty.usbmodem141221,raw,echo=0,clocal=1,cs8,nonblock=1,ixoff=0,ixon=0,ispeed=9600,ospeed=9600,crtscts=0 <-> openssl-connect:blynk-cloud.com:8441,cafile=/Users/kwhrjn/Documents/Arduino/libraries/blynk-library-master/scripts/certs/server.crt,nodelay
2018/04/19 22:30:24 socat[12056] N opening character device "/dev/tty.usbmodem141221" for reading and writing
2018/04/19 22:30:24 socat[12056] N opening connection to LEN=16 AF=2 188.166.206.43:8441
2018/04/19 22:30:24 socat[12056] N successfully connected from local address LEN=16 AF=2 192.168.0.13:56737
2018/04/19 22:30:25 socat[12056] N trusting certificate, commonName matches
2018/04/19 22:30:25 socat[12056] N SSL connection using ECDHE-RSA-AES128-GCM-SHA256
2018/04/19 22:30:25 socat[12056] N SSL connection compression "none"
2018/04/19 22:30:25 socat[12056] N SSL connection expansion "none"
2018/04/19 22:30:25 socat[12056] N starting data transfer loop with FDs [5,5] and [8,8]
I modified Blynk interface as shown below.
zeRGBa Settings: a component to control LEDs color. select a virtual pin "V0" and "MERGE" as output
Slider Settings: a component to control brightness. select a virtual pin "V1" and "SWITCH" as mode.
Button Settings: a component to select a color change pattern. select a virtual pin "V2" and "SWITCH" as mode.
Slider Settings: a component to control the speed of color change. select a virtual pin "V3"
I wrote an arduino sketch with reference to NeoPixel strandtest sketch to respond to the change of virtual pins (V0, V1, V2 and V3)'s values.
#include <BlynkSimpleStream.h>
#include <Adafruit_NeoPixel.h>
char auth[] = "b5b961bbfd0044bbac5a30f94e20d6d0";
#define PIN 19
#define NUMPIXELS 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85 ;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170 ;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
int ledR = 0;
int ledG = 0;
int ledB = 0;
int pixelBrightness = 50;
int Mode = 0, j = 0, Speed = 20;
BLYNK_WRITE(V0) //pick a color of LED
{
ledR = param[0].asInt();
ledG = param[1].asInt();
ledB = param[2].asInt();
for(int i=0; i < NUMPIXELS;i++){
strip.setPixelColor(i, strip.Color(ledR, ledG, ledB));
}
strip.show();
}
BLYNK_WRITE(V1) // parameter of LED brightness
{
pixelBrightness = param.asInt();
strip.setBrightness(pixelBrightness);
strip.show();
}
BLYNK_WRITE(V2) //parameter of the pattern of blinking
{
Mode = param.asInt();
}
BLYNK_WRITE(V3) //parameter of the speed of color change
{
Speed = param.asInt();
}
//a function of changing the color of LEDs like a rainbow
void rainbowCycle(uint8_t wait, uint8_t j) {
uint16_t i;
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(Serial, auth);
Blynk.syncAll();
strip.begin();
strip.setBrightness(pixelBrightness);
strip.show();
}
void loop()
{
Blynk.run();
strip.setBrightness(pixelBrightness);
if(Mode == 0){
//normal mode
for(int i=0; i < NUMPIXELS;i++){
strip.setPixelColor(i, strip.Color(ledR, ledG, ledB));
}
strip.show();
}else{
//rainbow mode
j++;
if(j >256){
j = 0;
}
rainbowCycle(Speed, j);
}
}
I connected my board which I designed in week 12(output devices) to a laptop via FabISP and FTDI cable. After uploading the sketch to my satshakit board, I could change the color of LEDS from blynk interface.