ordered files, added esp8266

This commit is contained in:
aster94
2019-01-06 18:41:58 +01:00
parent 6c6402743a
commit 9d714f940d
7 changed files with 647 additions and 614 deletions

View File

@@ -1,471 +1,471 @@
import processing.serial.*; import processing.serial.*;
import java.util.Arrays; import java.util.Arrays;
Serial p; Serial p;
//////////////////////////////////////////////// ////////////////////////////////////////////////
/*--------------------SETUP-------------------*/ /*--------------------SETUP-------------------*/
//uncomment the line where your arduino/STM32 is connected //uncomment the line where your arduino/STM32 is connected
//String LA_port = "/dev/ttyACM0"; //linux DFU //String LA_port = "/dev/ttyACM0"; //linux DFU
//String LA_port = "/dev/ttyUSB0"; //linux Serial //String LA_port = "/dev/ttyUSB0"; //linux Serial
String LA_port = "COM10"; //windows String LA_port = "COM10"; //windows
final int baudrate = 115200; //check if it is the same in arduino final int baudrate = 115200; //check if it is the same in arduino
//change it to true if you are using a STM32 instead of arduino //change it to true if you are using a STM32 instead of arduino
final boolean STM32 = false; final boolean STM32 = false;
/*------------------END SETUP-----------------*/ /*------------------END SETUP-----------------*/
//////////////////////////////////////////////// ////////////////////////////////////////////////
//colors: //colors:
int white = 255; int white = 255;
int black = 0; int black = 0;
int green = #00FF00; int green = #00FF00;
int grey = 150; int grey = 150;
// shift, reducer and millisecond view // shift, reducer and millisecond view
float reducer = 1.0; float reducer = 1.0;
boolean milliseconds = false; boolean milliseconds = false;
float xShift; float xShift;
// start point in the processing window // start point in the processing window
int xEdge = 60; int xEdge = 60;
int yEdge = 30; int yEdge = 30;
int xEnd; int xEnd;
float[] xPos = {0, 0, 0, 0, 0, 0}; float[] xPos = {0, 0, 0, 0, 0, 0};
int yBottom; int yBottom;
int yDiff; int yDiff;
int yPos = yEdge; int yPos = yEdge;
int ySave = yEdge; int ySave = yEdge;
boolean textCovered; boolean textCovered;
boolean drawTimes = true; boolean drawTimes = true;
//Serial from mcu //Serial from mcu
//initial data //initial data
int samples; int samples;
int event; int event;
int initialState; int initialState;
boolean first = false; boolean first = false;
boolean dataComplete = false; boolean dataComplete = false;
//following data //following data
boolean [][] state; boolean [][] state;
boolean [] isLow = new boolean[6]; boolean [] isLow = new boolean[6];
float[] usTime; float[] usTime;
float[] xTime; float[] xTime;
int[] pinChanged; int[] pinChanged;
//buttons and others //buttons and others
int button1X = 8; int button1X = 8;
int button2X = 8; int button2X = 8;
int button3X = 80; int button3X = 80;
int button4X = 200; int button4X = 200;
int button5X = 270; int button5X = 270;
int buttonY; int buttonY;
int buttonH = 20; int buttonH = 20;
int smallButtonW = 50; int smallButtonW = 50;
int bigButtonW = 100; int bigButtonW = 100;
int graphBoxH; int graphBoxH;
int textBoxH; int textBoxH;
int immage = 1; int immage = 1;
int corner = 10; int corner = 10;
// bar scroll // bar scroll
int handleFill = grey; int handleFill = grey;
float handleX; float handleX;
float handleY; float handleY;
float handleW = 20; float handleW = 20;
float handleH = 15; float handleH = 15;
boolean isDraggable = false; boolean isDraggable = false;
void setup () { void setup () {
//p = new Serial(this, Serial.list()[0], 115200); //p = new Serial(this, Serial.list()[0], 115200);
p = new Serial(this, LA_port, baudrate); p = new Serial(this, LA_port, baudrate);
p.bufferUntil('\n'); p.bufferUntil('\n');
size(1000, 460); size(1000, 460);
background(black); background(black);
smooth(4); smooth(4);
graphBoxH = height -50; graphBoxH = height -50;
textBoxH = height - 35; textBoxH = height - 35;
yBottom = graphBoxH-20; yBottom = graphBoxH-20;
buttonY = textBoxH +8; buttonY = textBoxH +8;
handleX = xEdge; handleX = xEdge;
handleY = graphBoxH; handleY = graphBoxH;
} }
void cleanGraph() { void cleanGraph() {
noStroke(); //no borders noStroke(); //no borders
fill(black); fill(black);
rect(xEdge, 0, width, graphBoxH); //cancel the graph rect(xEdge, 0, width, graphBoxH); //cancel the graph
stroke(green); //green lines stroke(green); //green lines
Arrays.fill(xPos, 0); //reset start point of the graph Arrays.fill(xPos, 0); //reset start point of the graph
textCovered = false; textCovered = false;
} }
void draw () { void draw () {
if (dataComplete==true) { if (dataComplete==true) {
cleanGraph(); cleanGraph();
pushMatrix(); //move the coordinate reference pushMatrix(); //move the coordinate reference
translate(xEdge, 0); translate(xEdge, 0);
for (int i=0; i<samples; i++) { for (int i=0; i<samples; i++) {
yPos = yEdge; //start a new cicle yPos = yEdge; //start a new cicle
for (int n=0; n<6; n++) { for (int n=0; n<6; n++) {
if (state[i][n]==true) { if (state[i][n]==true) {
ySave = yPos; //save y value ySave = yPos; //save y value
if (isLow[n]==true) { //pin high else low if (isLow[n]==true) { //pin high else low
yDiff=yPos; yDiff=yPos;
yPos+=30; yPos+=30;
isLow[n]=false; isLow[n]=false;
} else { } else {
yDiff=yPos+30; yDiff=yPos+30;
isLow[n]=true; isLow[n]=true;
} }
// Text times // Text times
if (drawTimes == true) { if (drawTimes == true) {
stroke(grey); stroke(grey);
fill(grey); fill(grey);
textSize(10); textSize(10);
textCovered=!textCovered; textCovered=!textCovered;
dashline(xTime[i]+xShift, yPos, xTime[i]+xShift, yBottom, spacing); dashline(xTime[i]+xShift, yPos, xTime[i]+xShift, yBottom, spacing);
text(round(usTime[i]), xTime[i]+xShift+2, (textCovered==true) ? yBottom : yBottom+10); //write on different height text(round(usTime[i]), xTime[i]+xShift+2, (textCovered==true) ? yBottom : yBottom+10); //write on different height
stroke(green); stroke(green);
} }
// Graph lines // Graph lines
line(xPos[n]+xShift, yPos, xTime[i]+xShift, yPos); // straight line line(xPos[n]+xShift, yPos, xTime[i]+xShift, yPos); // straight line
line(xTime[i]+xShift, yPos, xTime[i]+xShift, yDiff); // vertical line line(xTime[i]+xShift, yPos, xTime[i]+xShift, yDiff); // vertical line
xPos[n]=xTime[i]; //save last position of the line for the pin xPos[n]=xTime[i]; //save last position of the line for the pin
yPos = ySave; //load the initial value of the y yPos = ySave; //load the initial value of the y
} }
yPos+=60; //go to the next pin yPos+=60; //go to the next pin
} }
} }
if (samples!=0) { if (samples!=0) {
xEnd = int (xTime[samples-1]) +10; xEnd = int (xTime[samples-1]) +10;
} else { } else {
xEnd = 0; xEnd = 0;
} }
yPos = yEdge; yPos = yEdge;
for (int n = 0; n < 6; n++) { for (int n = 0; n < 6; n++) {
if (xPos[n]!=0) { //draw only the pin which are active if (xPos[n]!=0) { //draw only the pin which are active
if (isLow[n]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); if (isLow[n]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30);
else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos);
} }
yPos+=60; yPos+=60;
} }
dataComplete = false; dataComplete = false;
popMatrix(); popMatrix();
} }
drawText(); drawText();
} }
void drawText() { void drawText() {
stroke(white); //white borders stroke(white); //white borders
fill(black); fill(black);
rect(0, 0, xEdge, graphBoxH); //clean left side rect(0, 0, xEdge, graphBoxH); //clean left side
rect(xEdge, graphBoxH, width, handleH); //clean bar scroll rect(xEdge, graphBoxH, width, handleH); //clean bar scroll
rect(0, textBoxH, width, height); //clean bottom side rect(0, textBoxH, width, height); //clean bottom side
// write name of the pins // write name of the pins
fill(white); fill(white);
textSize(14); textSize(14);
int x=10; int x=10;
int y=50; int y=50;
if (STM32) { if (STM32) {
for (byte i = 12; i<=15; i++) { for (byte i = 12; i<=15; i++) {
line(x, y-20, xEdge, y-20); line(x, y-20, xEdge, y-20);
line(x, y+10, xEdge, y+10); line(x, y+10, xEdge, y+10);
text ("PB"+i, x, y); text ("PB"+i, x, y);
y+=60; y+=60;
} }
} else { } else {
for (byte i = 8; i<=13; i++) { for (byte i = 8; i<=13; i++) {
line(x, y-20, xEdge, y-20); line(x, y-20, xEdge, y-20);
line(x, y+10, xEdge, y+10); line(x, y+10, xEdge, y+10);
text ("Pin "+i, x, y); text ("Pin "+i, x, y);
y+=60; y+=60;
} }
} }
// draw buttons // draw buttons
fill(grey); fill(grey);
rect(button1X, yBottom-15, smallButtonW, buttonH, corner); rect(button1X, yBottom-15, smallButtonW, buttonH, corner);
rect(button2X, buttonY, smallButtonW, buttonH, corner); rect(button2X, buttonY, smallButtonW, buttonH, corner);
rect(button3X, buttonY, bigButtonW, buttonH, corner); rect(button3X, buttonY, bigButtonW, buttonH, corner);
rect(button4X, buttonY, smallButtonW, buttonH, corner); rect(button4X, buttonY, smallButtonW, buttonH, corner);
rect(button5X, buttonY, smallButtonW, buttonH, corner); rect(button5X, buttonY, smallButtonW, buttonH, corner);
fill(white); fill(white);
text("T:"+ str (drawTimes), button1X+3, yBottom); text("T:"+ str (drawTimes), button1X+3, yBottom);
text("Start", button2X+3, buttonY+14); text("Start", button2X+3, buttonY+14);
text(milliseconds == true ? "milliseconds" : "microseconds", button3X+3, buttonY+14); text(milliseconds == true ? "milliseconds" : "microseconds", button3X+3, buttonY+14);
text(reducer, button4X+3, buttonY+14); text(reducer, button4X+3, buttonY+14);
text("Save", button5X+3, buttonY+14); text("Save", button5X+3, buttonY+14);
//bar scroll //bar scroll
fill(handleFill); fill(handleFill);
rect(handleX, handleY, handleW, handleH); rect(handleX, handleY, handleW, handleH);
if (isDraggable) { if (isDraggable) {
handleX = mouseX-(handleW/2); handleX = mouseX-(handleW/2);
if (handleX<xEdge) handleX = xEdge; if (handleX<xEdge) handleX = xEdge;
if (handleX>width-handleW) handleX = width-handleW; if (handleX>width-handleW) handleX = width-handleW;
getData(); getData();
xShift = -map(handleX, xEdge, width-handleW, 0, xEnd-900); xShift = -map(handleX, xEdge, width-handleW, 0, xEnd-900);
} }
} }
void mousePressed() { void mousePressed() {
if (mouseX>handleX && mouseX<handleX+handleW && if (mouseX>handleX && mouseX<handleX+handleW &&
mouseY>handleY && mouseY<handleY+handleH) { mouseY>handleY && mouseY<handleY+handleH) {
isDraggable = true; isDraggable = true;
handleFill = color(100, 200, 255); handleFill = color(100, 200, 255);
} }
} }
void mouseReleased() { void mouseReleased() {
isDraggable = false; isDraggable = false;
handleFill = grey; handleFill = grey;
} }
void mouseClicked() { void mouseClicked() {
// draw times // draw times
if (mouseY>yBottom-15 && mouseY <yBottom-15+buttonH && if (mouseY>yBottom-15 && mouseY <yBottom-15+buttonH &&
mouseX>button1X && mouseX <button1X+smallButtonW) { mouseX>button1X && mouseX <button1X+smallButtonW) {
drawTimes = !drawTimes; drawTimes = !drawTimes;
getData(); getData();
} }
// new read // new read
if (mouseY>buttonY && mouseY <buttonY+buttonH && if (mouseY>buttonY && mouseY <buttonY+buttonH &&
mouseX>button2X && mouseX <button2X+smallButtonW) { mouseX>button2X && mouseX <button2X+smallButtonW) {
p.write('G'); p.write('G');
println("new data coming"); println("new data coming");
p.clear(); p.clear();
xShift = 0; xShift = 0;
handleX = xEdge; handleX = xEdge;
} }
// micro or millis // micro or millis
if (mouseY>buttonY && mouseY <buttonY+buttonH && if (mouseY>buttonY && mouseY <buttonY+buttonH &&
mouseX>button3X && mouseX <button3X+bigButtonW) { mouseX>button3X && mouseX <button3X+bigButtonW) {
milliseconds = !milliseconds; milliseconds = !milliseconds;
if (milliseconds == true) { if (milliseconds == true) {
for (int i=0; i< samples; i++) usTime[i] /= 1000.0; for (int i=0; i< samples; i++) usTime[i] /= 1000.0;
} }
if (milliseconds== false) { if (milliseconds== false) {
for (int i=0; i< samples; i++) usTime[i] *= 1000.0; for (int i=0; i< samples; i++) usTime[i] *= 1000.0;
} }
getData(); getData();
xShift = 0; xShift = 0;
handleX = xEdge; handleX = xEdge;
} }
//save frame //save frame
if (mouseY>buttonY && mouseY <buttonY+buttonH && if (mouseY>buttonY && mouseY <buttonY+buttonH &&
mouseX>button5X && mouseX <button5X+smallButtonW) { mouseX>button5X && mouseX <button5X+smallButtonW) {
String a = "la_capture-"+immage; //+".jpg"; //if you prefer this format, default .tif String a = "la_capture-"+immage; //+".jpg"; //if you prefer this format, default .tif
save(a); save(a);
immage++; immage++;
} }
} }
void mouseWheel(MouseEvent event) { void mouseWheel(MouseEvent event) {
float wheel = event.getCount(); float wheel = event.getCount();
if (mouseY>buttonY && mouseY <buttonY+buttonH && if (mouseY>buttonY && mouseY <buttonY+buttonH &&
mouseX>button4X && mouseX <button4X+smallButtonW) { mouseX>button4X && mouseX <button4X+smallButtonW) {
//it is over the reducer button //it is over the reducer button
xShift *= reducer; xShift *= reducer;
reducer-= wheel/10; reducer-= wheel/10;
reducer = constrain(reducer, 0.1, 9.9); reducer = constrain(reducer, 0.1, 9.9);
xShift /= reducer; // preserve scroll position xShift /= reducer; // preserve scroll position
getData(); getData();
} else { //move the graph } else { //move the graph
xShift-=wheel*50; xShift-=wheel*50;
getData(); getData();
} }
} }
void mouseMoved() { void mouseMoved() {
if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button2X && mouseX <button2X+smallButtonW) { if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button2X && mouseX <button2X+smallButtonW) {
cursor(HAND); cursor(HAND);
} else if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button3X && mouseX <button3X+bigButtonW) { } else if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button3X && mouseX <button3X+bigButtonW) {
cursor(HAND); cursor(HAND);
} else if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button5X && mouseX <button5X+smallButtonW) { } else if (mouseY>buttonY && mouseY <buttonY+buttonH && mouseX>button5X && mouseX <button5X+smallButtonW) {
cursor(HAND); cursor(HAND);
} else if (mouseY>yBottom-15 && mouseY <yBottom-15+buttonH && mouseX>button1X && mouseX <button1X+smallButtonW) { } else if (mouseY>yBottom-15 && mouseY <yBottom-15+buttonH && mouseX>button1X && mouseX <button1X+smallButtonW) {
cursor(HAND); cursor(HAND);
} else if (mouseX>handleX && mouseX<handleX+handleW && mouseY>handleY && mouseY<handleY+handleH) { } else if (mouseX>handleX && mouseX<handleX+handleW && mouseY>handleY && mouseY<handleY+handleH) {
cursor(HAND); cursor(HAND);
} else { } else {
cursor(ARROW); cursor(ARROW);
} }
} }
void serialEvent (Serial p) { void serialEvent (Serial p) {
String inString = p.readStringUntil('\n'); String inString = p.readStringUntil('\n');
inString = trim(inString); inString = trim(inString);
println("incoming: "+inString); println("incoming: "+inString);
if (inString.equals("S") == true) { if (inString.equals("S") == true) {
initialState=0; initialState=0;
samples=0; samples=0;
event=-2; event=-2;
first = true; first = true;
} else { } else {
String list [] = split(inString, ':'); String list [] = split(inString, ':');
if (first == true) { if (first == true) {
initialState = int (list[0]); initialState = int (list[0]);
samples = int (list[1]); samples = int (list[1]);
pinChanged = new int[samples]; pinChanged = new int[samples];
usTime = new float[samples]; usTime = new float[samples];
xTime = new float[samples]; xTime = new float[samples];
state = new boolean[samples][6]; state = new boolean[samples][6];
first = false; first = false;
} else { } else {
pinChanged[event] = int (list[0]); pinChanged[event] = int (list[0]);
usTime[event] = float (list[1]); usTime[event] = float (list[1]);
} }
} }
event++; event++;
if (event == samples) { if (event == samples) {
getData(); getData();
} }
} }
void getData () { void getData () {
//check data: //check data:
println("event: "+event); println("event: "+event);
println("initial: "+initialState); println("initial: "+initialState);
println("samples: "+samples); println("samples: "+samples);
//println("pin"+changed[0]); //println("pin"+changed[0]);
//println("time"+usTime[0]); //println("time"+usTime[0]);
printArray(usTime); printArray(usTime);
printArray(xTime); printArray(xTime);
//println("pin: "+binary(changed[0], 6)); //println("pin: "+binary(changed[0], 6));
for (int i = 0; i < samples; i++) { for (int i = 0; i < samples; i++) {
xTime[i] = usTime[i] / reducer; //better to reduce the lenght of the x xTime[i] = usTime[i] / reducer; //better to reduce the lenght of the x
} }
int b; int b;
int mask = 1; int mask = 1;
// initial state // initial state
for (int n=0; n<6; n++) { for (int n=0; n<6; n++) {
b = initialState & mask; b = initialState & mask;
isLow[n] = !boolean (b); isLow[n] = !boolean (b);
mask <<= 1; mask <<= 1;
//println("islow: "+isLow[n]); //println("islow: "+isLow[n]);
} }
// changes // changes
for (int i=0; i<samples; i++) { for (int i=0; i<samples; i++) {
mask = 1; mask = 1;
//println("i:"+i); //println("i:"+i);
//println(binary(changed[i], 6)); //println(binary(changed[i], 6));
for (int n=0; n<6; n++) { for (int n=0; n<6; n++) {
b= pinChanged[i] & mask; b= pinChanged[i] & mask;
state[i][n]= boolean (b); state[i][n]= boolean (b);
mask <<= 1; mask <<= 1;
//println(state[i][n]); //println(state[i][n]);
} }
} }
dataComplete = true; dataComplete = true;
} }
float[] spacing = {5, 8}; //used for the dashline function, pixels float[] spacing = {5, 8}; //used for the dashline function, pixels
void dashline(float x0, float y0, float x1, float y1, float[] spacing) { void dashline(float x0, float y0, float x1, float y1, float[] spacing) {
float distance = dist(x0, y0, x1, y1); float distance = dist(x0, y0, x1, y1);
float [ ] xSpacing = new float[spacing.length]; float [ ] xSpacing = new float[spacing.length];
float [ ] ySpacing = new float[spacing.length]; float [ ] ySpacing = new float[spacing.length];
float drawn = 0.0; // amount of distance drawn float drawn = 0.0; // amount of distance drawn
if (distance > 0) if (distance > 0)
{ {
int i; int i;
boolean drawLine = true; // alternate between dashes and gaps boolean drawLine = true; // alternate between dashes and gaps
/* /*
Figure out x and y distances for each of the spacing values Figure out x and y distances for each of the spacing values
I decided to trade memory for time; I'd rather allocate I decided to trade memory for time; I'd rather allocate
a few dozen bytes than have to do a calculation every time a few dozen bytes than have to do a calculation every time
I draw. I draw.
*/ */
for (i = 0; i < spacing.length; i++) for (i = 0; i < spacing.length; i++)
{ {
xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance);
ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance);
} }
i = 0; i = 0;
while (drawn < distance) while (drawn < distance)
{ {
if (drawLine) if (drawLine)
{ {
line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]);
} }
x0 += xSpacing[i]; x0 += xSpacing[i];
y0 += ySpacing[i]; y0 += ySpacing[i];
/* Add distance "drawn" by this line or gap */ /* Add distance "drawn" by this line or gap */
drawn = drawn + mag(xSpacing[i], ySpacing[i]); drawn = drawn + mag(xSpacing[i], ySpacing[i]);
i = (i + 1) % spacing.length; // cycle through array i = (i + 1) % spacing.length; // cycle through array
drawLine = !drawLine; // switch between dash and gap drawLine = !drawLine; // switch between dash and gap
} }
} }
} }

View File

@@ -1,8 +1,17 @@
/*
* ESP8266.ino
*
* Author : yoursunny
* Led: LED_BUILTIN
*/
#include <c_types.h> #include <c_types.h>
#define baudrate 115200 // check if it is the same in processing
// number of samples to collect // number of samples to collect
static const int N_SAMPLES = 300; static const int N_SAMPLES = 300;
// what pins to use, between 0 and 15 // what pins to use, between 0 and 15
static const int PIN0 = 4; static const int PIN0 = 4;
static const int PIN1 = 5; static const int PIN1 = 5;
@@ -18,7 +27,7 @@ static_assert(PIN3 >= 0 && PIN3 < 16, "");
static constexpr uint32_t MASK = (1 << PIN0) | (1 << PIN1) | (1 << PIN2) | (1 << PIN3); static constexpr uint32_t MASK = (1 << PIN0) | (1 << PIN1) | (1 << PIN2) | (1 << PIN3);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(baudrate);
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);

View File

@@ -1,16 +1,18 @@
/* /*
* LA.cpp * MEGA.ino
* *
* Created: 11/12/2016 19.35.51 * Created: 11/12/2016 19.35.51
* Author : Vincenzo * Author : Vincenzo / sancho
* Modificaciones agregadas para funcionar con ArduinoMega2560 por Enmanuel Sancho Quintanilla * Modificaciones agregadas para funcionar con ArduinoMega2560 por Enmanuel Sancho Quintanilla
* La unidad minima en tiempo para este sistema es de 8 micro segundos lo que idealmente permitiria * La unidad minima en tiempo para este sistema es de 8 micro segundos lo que idealmente permitiria
* observar clocks con periodos de 62 kHz sin embargo para poder apreciar las señales logicas con suficiente * observar clocks con periodos de 62 kHz sin embargo para poder apreciar las señales logicas con suficiente
* resolucion se recomienda no superar los 30 kHz en el clock del sistema. * resolucion se recomienda no superar los 30 kHz en el clock del sistema.
*/ */
#define baudrate 115200 //check if it is the same in processing #define baudrate 115200 // check if it is the same in processing
#define samples 10 #define samples 200 // the number of samples you want to take
#define pin_used #define pin_used
#define timezerooffset 125 //microsegundos #define timezerooffset 125 //microsegundos
#define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos. #define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos.

View File

@@ -1,11 +1,18 @@
/* /*
Author : Vincenzo G * STM32F1.ino
https://www.hackster.io/vincenzo-g/diy-logic-analyzer-f61ee5 *
* Author : Vincenzo
*/ * this works using the unofficial STM32 core, more info: https://github.com/rogerclarkmelbourne/Arduino_STM32
* Led: PB1
*/
#define samples 300
#define baudrate 115200 // check if it is the same in processing
#define samples 200 // the number of samples you want to take
#define boardLed PB1 #define boardLed PB1
uint8_t initial, state, old_state; uint8_t initial, state, old_state;
uint8_t pinChanged[samples]; uint8_t pinChanged[samples];
uint32_t timer[samples]; uint32_t timer[samples];
@@ -16,7 +23,7 @@ uint16_t event = 0;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(baudrate);
pinMode (boardLed, OUTPUT); pinMode (boardLed, OUTPUT);
digitalWrite(boardLed, LOW); digitalWrite(boardLed, LOW);

View File

@@ -1,125 +1,126 @@
/* /*
* LA.cpp * UNO.ino
* *
* Created: 11/12/2016 19.35.51 * Created: 11/12/2016 19.35.51
* Author : Vincenzo * Author : Vincenzo
*/ * Led on A0
*/
#define baudrate 115200 //check if it is the same in processing
#define samples 200 #define baudrate 115200 // check if it is the same in processing
#define samples 200 // the number of samples you want to take
#define F_CPU 16000000UL
#include <avr/io.h> #define F_CPU 16000000UL
#include <avr/interrupt.h> #include <avr/io.h>
#include <util/delay.h> #include <avr/interrupt.h>
#define prescaler 0x02 #include <util/delay.h>
volatile uint16_t timer1_overflow_count; #define prescaler 0x02
volatile uint16_t timer1_overflow_count;
uint8_t initial, state, old_state;
uint8_t pinChanged[samples]; uint8_t initial, state, old_state;
uint32_t timer[samples]; uint8_t pinChanged[samples];
uint16_t event = 0; uint32_t timer[samples];
uint16_t event = 0;
void init_board() {
void init_board() {
PORTC = (0 << 0); DDRC |= (1 << 0); // led A0
DDRB |= 0x00; // pin 8-13 input PORTC = (0 << 0); DDRC |= (1 << 0); // led A0
PORTB |= 0x3F; // pull-up DDRB |= 0x00; // pin 8-13 input
PORTB |= 0x3F; // pull-up
}
}
void init_timer() {
void init_timer() {
//clear
TCCR1A = 0b00000000; //clear
TCCR1B = 0b00000000; TCCR1A = 0b00000000;
TIMSK1 = 0b00000000; TCCR1B = 0b00000000;
TIMSK1 = 0b00000000;
//settings
TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation //settings
TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation
TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation
TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation
TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler
sei(); //enable interrupts
TIMSK1 |= (1 << TOIE1); // enable overflow interrupt sei(); //enable interrupts
TIMSK1 |= (1 << TOIE1); // enable overflow interrupt
}
}
ISR(TIMER1_OVF_vect) {
timer1_overflow_count++; ISR(TIMER1_OVF_vect) {
} timer1_overflow_count++;
}
void reset_timer1 () {
TCNT1 = 0; void reset_timer1 () {
timer1_overflow_count = 0; TCNT1 = 0;
} timer1_overflow_count = 0;
}
uint32_t myMicros () {
cli(); uint32_t myMicros () {
cli();
if (TIFR1 & (1 << TOV1)) {
TIFR1 = (0 << TOV1); if (TIFR1 & (1 << TOV1)) {
timer1_overflow_count++; TIFR1 = (0 << TOV1);
} timer1_overflow_count++;
}
uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2;
sei(); uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2;
return total_time; sei();
} return total_time;
}
void start() {
_delay_ms(1000); void start() {
_delay_ms(1000);
reset_timer1();
event = 0; reset_timer1();
event = 0;
PORTC = (1 << 0);
initial = PINB; PORTC = (1 << 0);
state = initial; initial = PINB;
state = initial;
}
}
void sendData() {
PORTC = (0 << 0); //turn off led void sendData() {
PORTC = (0 << 0); //turn off led
//initial data
Serial.println("S"); //initial data
Serial.print(initial); Serial.print(":"); Serial.println("S");
Serial.println(samples); Serial.print(initial); Serial.print(":");
Serial.println(samples);
//data
for (int i = 0; i < samples; i++) { //data
Serial.print(pinChanged[i]); Serial.print(":"); for (int i = 0; i < samples; i++) {
Serial.println(timer[i]); Serial.print(pinChanged[i]); Serial.print(":");
} Serial.println(timer[i]);
} }
}
int main(void) {
Serial.begin(baudrate); int main(void) {
Serial.begin(baudrate);
init_board();
init_timer(); init_board();
init_timer();
start();
start();
while (1) {
while (1) {
old_state = state;
state = PINB; old_state = state;
state = PINB;
if (old_state != state) {
timer[event] = myMicros(); if (old_state != state) {
pinChanged[event] = state ^ old_state; timer[event] = myMicros();
event++; pinChanged[event] = state ^ old_state;
event++;
if (event == samples) {
sendData(); if (event == samples) {
while (Serial.read() != 'G') ; //wait for the "go" sendData();
start(); while (Serial.read() != 'G') ; //wait for the "go"
} start();
} }
} }
} }
}

View File

@@ -1,32 +1,39 @@
# Logic Analyzer # Logic Analyzer
A few days ago I needed a logic sniffer since I don't have any I thought to write my own code. It will work on every Arduino board or AVR and STM32. It could be very helpful to debug ISP, I2C and other serial communication where you think that could be an error. A few days ago I needed a logic analyzer since I don't have any (and them are quite expensive) I thought to write my own code. It will work on every Arduino board, AVR, STM32 and ESP8266. It could be very helpful to debug ISP, I2C and other serial communication where you think that could be an error.
![la](https://image.ibb.co/mEAvfU/3.jpg) ![la](https://image.ibb.co/mEAvfU/3.jpg)
## Usage ## Usage
- upload to your board "UNO.ino" or "MEGA.ino" or "STM32.ino" - Upload `UNO.ino`, `MEGA.ino`, `STM32F1.ino` or `ESP8266.ino` to your board
- choose your board and serial port on "processing.pde" - choose your board and serial port on `processing.pde`
- run it and have a good debug :D - run it and have a good debug :D
If you wish you could put a led on the arduino pin A0 to see when the MCU is recording, the number of samples is set to 200 but you could increment it until the memory is full. If you wish you could put a LED to see when the MCU is recording, see the code of your board to know where to wire it. The number of samples is set to 200 but you could increment it until the memory is full.
To have it faster than possible the loop was reduced to the minimum number of statement and I am doing a lot of optimization! All the calculation are made after saving the data, and during the recording there are stored only the values of the pin that changed and when it happened. To have it faster than possible the loop was reduced to the minimum number of statement and I am doing a lot of optimization! All the calculation are made after saving the data, and during the recording there are stored only the values of the pin that changed and when it happened.
I made a processing sketch to visualize it. Using the bar scroll at the bottom of the graph you could move along the captures or alternatively you could use the wheel of the mouse. With the "Start" button you can begin a new recording. Two divider have been added: one to use millisecond instead of microsecond and the other that work like a kind of "zoom" (to change it move the mouse over this button than use the mouse wheel; decreasing it you will zoom in, increasing zoom out). You are also able to save the current window in a .jpg or .tif file with the "Save" button. I made a processing sketch to visualize it. Using the bar scroll at the bottom of the graph you could move along the captures or alternatively you could use the wheel of the mouse. With the "Start" button you can begin a new recording. Two divider have been added: one to use millisecond instead of microsecond and the other that work like a kind of "zoom" (to change it move the mouse over this button than use the mouse wheel; decreasing it you will zoom in, increasing zoom out). You are also able to save the current window in a .jpg or .tif file with the "Save" button.
It works on windows and Linux both 32 64 bit and android devices. I added also an Arduino test sketch if you would like to test this logic analyzer. It works on Windows and Linux both 32 64 bit and android devices. I added also an Arduino test sketch if you would like to test the logic analyzer.
Enjoy! Enjoy!
## Requisites
- [Arduino IDE](https://www.arduino.cc/en/main/software)
- [Processing](https://processing.org/download/)
# Change Log # Change Log
##### 06/01/19
- ESP8266 version by @yoursunny, who also made a few improvements to processing, thanks!
##### 30/08/18 ##### 30/08/18
- MEGA version added by @sancho11, which now is a collaborator - MEGA version added by @sancho11 but the processing interface is not compatible for all the pins
##### 29/04/17 ##### 29/04/17
- added support for STM32 - added support for STM32F1 using the [Arduino_STM32 core](https://github.com/rogerclarkmelbourne/Arduino_STM32)
##### 15/12/16 ##### 15/12/16
- improved acquisition code - improved acquisition code

View File

@@ -1,3 +1,10 @@
/*
* tester.ino
*
* Author : Vincenzo
* Test your logic analyzer with another arduino
*/
#define led A5 #define led A5
#define led2 13 #define led2 13