Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Yellowsnow's Teensy 3.2 oscilloscope
- Code for Teensy
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Yellowsnow's Oscilloscope Free for use..instructions https://www.youtube.com/watch?v=VQwh-y2jW_c
- #define pin A0
- int sample[1000];
- int x = 0;
- unsigned long startTime = 0;
- unsigned long stopTime = 0;
- int startSample = 0;
- int sampleTime = 1000; // sample time length in microseconds
- int samplesTaken = 0;
- char incomingMess = 0;
- int dump = 0;
- void setup() {
- pinMode(pin, INPUT);
- Serial.begin(115200);
- }
- void loop() {
- if (Serial.available() > 0) {
- incomingMess = Serial.read();
- messDo();
- }
- if(startSample == 1) {
- x = 0;
- startTime = micros();
- stopTime = startTime + sampleTime;
- while(micros() <= stopTime && x <= 999) {
- sample[x] = analogRead(pin);
- x = x + 1;
- }
- samplesTaken = x;
- startSample = 0;
- }
- }
- void messDo() {
- if(incomingMess == 'T') { // T=start
- startSample = 1;
- }
- if(incomingMess == 'S') { // S=sendsample
- sendSample();
- }
- if(incomingMess == 'A') { // A=send amount of samples taken
- sendAmount();
- }
- }
- void sendSample() {
- x = 0;
- while(x <= samplesTaken) {
- dump = sample[x];
- Serial.println(dump);
- x = x + 1;
- }
- Serial.println("8888");
- }
- void sendAmount() {
- Serial.println(samplesTaken);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Code for Processing
- // Yellowsnow's Oscilloscope Free for use..instructions https://www.youtube.com/watch?v=VQwh-y2jW_c
- import processing.serial.*;
- Serial port;
- float x = 0;
- float xLS = 0;
- int time = 1;
- int timeLS = 0;
- int volts = 0;
- int readyToRead = 0; // 1=ready to read samples, 2=getting sample amount
- float num = 0;
- int sampleCount = 0;
- int T = 0;
- float[] sample = new float[1000];
- int G = 0;
- int M = 0;
- void setup() {
- size(1000, 600);
- port = new Serial(this, "/dev/ttyACM0", 115200); // windows "COM3"
- port.bufferUntil('\n');
- grid();
- }
- void draw() {
- if(readyToRead == 1) {
- num = sample[G];
- num = map(num, 0, 1023, 520, 20);
- stroke(#FC0D29);
- strokeWeight(4);
- line(timeLS, xLS, M, num);
- xLS = num;
- timeLS = M;
- M = M + 9; // change if you change sample time 1000micro best at 9, lower number for longer sampletime
- if(G >= 999) {
- G = 0;
- } else {
- G = G + 1;
- }
- }
- }
- void grid() {
- background(0);
- stroke(255);
- strokeWeight(1);
- line(0, 520, 1000, 520); //zero
- line(0, 445, 1000, 445); //.5 volt
- line(0, 370, 1000, 370); //1volt
- line(0, 295, 1000, 295); //1.5volt
- line(0, 220, 1000, 220); //2volt
- line(0, 145, 1000, 145); //2.5volt
- line(0, 70, 1000, 70); //3volt
- line(0, 20, 1000, 20); //3.3 volt
- fill(255);
- textSize(20);
- text("0", 950, 520);
- text("0.5V", 950, 445);
- text("1V", 950, 370);
- text("1.5V", 950, 295);
- text("2V", 950, 220);
- text("2.5V", 950, 145);
- text("3V", 950, 70);
- text("3.3V", 950, 20);
- fill(#29F227);
- rect(100, 530, 100, 60);
- rect(700, 530, 200, 60);
- fill(#F2FC27);
- rect(300, 530, 250, 60);
- fill(#ED4E32);
- rect(590, 530, 80, 60);
- textSize(25);
- fill(0);
- text("START", 110, 570);
- textSize(25);
- text("get sample amount", 310, 558);
- text("Get samples", 710, 570);
- text("Clear", 600, 570);
- }
- void serialEvent (Serial port) {
- if(readyToRead == 1) {
- sample[T] = float(port.readStringUntil('\n'));
- T = T + 1;
- } else {
- x = float(port.readStringUntil('\n'));
- }
- }
- void mousePressed() {
- if(mouseX >= 100 && mouseX <= 200 && mouseY >= 530 && mouseY <= 590) {
- port.write('T');
- }
- if(mouseX >= 300 && mouseX <= 550 && mouseY >= 530 && mouseY <= 590) {
- readyToRead = 2;
- port.write('A');
- delay(30);
- fill(0);
- textSize(25);
- text(x, 320, 585);
- }
- if(mouseX >= 700 && mouseX <= 900 && mouseY >= 530 && mouseY <= 590) {
- readyToRead = 1;
- T = 0;
- port.write('S');
- }
- if(mouseX >= 590 && mouseX <= 670 && mouseY >= 530 && mouseY <= 590) {
- grid();
- readyToRead = 0;
- timeLS = 0;
- xLS = 0;
- G = 0;
- M = 0;
- num = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement