Introduction: Linkit One Oscilloscope

Picture of Linkit One Oscilloscope

In this instructable I'm going to show you how to turn your Linkit One into an oscilloscope. Oscilloscope is a must tool if you are working with electronics but it costs a lot, but with a Linkit one you can create one at you home. The input to the oscilloscope is a analog pin so it can read both digital and analog data. In this instuctable I will also show you how to generate a square wave with an Arduino and display that wave on the oscilloscope.

Step 1: Requirements

Picture of Requirements

Here is a list of all the electronic components required to get started with the circuit.

LinkIt One

Arduino

Connecting wires

Step 2: Circuit

Picture of Circuit

There is not much of a circuit, the signal is applied across the Linkit One analog pin 0 and Gnd.

Note: The voltage of the signal should not exceed 5V as voltages above 5V can fry the board. This poject is made to read data from Arduino compatible sensors and if you want it to read higher voltages you would require a voltage converter.

Step 3: Linkit One

The code can be found below and you will require a modified Arduino IDE to work with the LinkIt One board to upload the code.

#define ANALOG_IN 0

void setup() {

Serial.begin(9600);

//Serial.begin(115200);

} void loop() {

int val = analogRead(ANALOG_IN);

Serial.write( 0xff );

Serial.write( (val >> 8) & 0xff );

Serial.write( val & 0xff );

}

Step 4: Square Wave Generator

Picture of Square Wave Generator

To test the circuit we just built we will be using an arduino to generate a square wave and the wave is going to be displayed on a PC screen via an arduino. The code to be uploaded to the arduino can be found below.

#include "Waveforms.h"

#define oneHzSample 1000000/maxSamplesNum // sample for the 1Hz signal expressed in microseconds

const int button0 = 2, button1 = 3; volatile int wave0 = 0, wave1 = 0;

int i = 0; int sample;

void setup() { analogWriteResolution(12); // set the analog output resolution to 12 bit (4096 levels) analogReadResolution(12); // set the analog input resolution to 12 bit

attachInterrupt(button0, wave0Select, RISING); // Interrupt attached to the button connected to pin 2 attachInterrupt(button1, wave1Select, RISING); // Interrupt attached to the button connected to pin 3 }

void loop() { // Read the the potentiometer and map the value between the maximum and the minimum sample available // 1 Hz is the minimum freq for the complete wave // 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time sample = map(analogRead(A0), 0, 4095, 0, oneHzSample); sample = constrain(t_sample, 0, oneHzSample);

analogWrite(DAC0, waveformsTable[wave0][i]); // write the selected waveform on DAC0 analogWrite(DAC1, waveformsTable[wave1][i]); // write the selected waveform on DAC1

i++; if(i == maxSamplesNum) // Reset the counter to repeat the wave i = 0;

delayMicroseconds(sample); // Hold the sample value for the sample time }

// function hooked to the interrupt on digital pin 2 void wave0Select() { wave0++; if(wave0 == 4) wave0 = 0; }

// function hooked to the interrupt on digital pin 3 void wave1Select() { wave1++; if(wave1 == 4) wave1 = 0; }

Step 5: Processing

Picture of Processing

For the computer software to display the wave we would be using processing, you need download processing and copy the code below and paste it in processing. Make sure you select a suitable COM port at which the Linkit one is connected.

import processing.serial.*;

Serial port; // Create object from Serial class int val; // Data received from the serial port int[] values; float zoom;

void setup() { size(1280, 480); // Open the port that the board is connected to and use the same speed (9600 bps) port = new Serial(this, Serial.list()[0], 9600); values = new int[width]; zoom = 1.0f; smooth(); }

int getY(int val) { return (int)(height - val / 1023.0f * (height - 1)); }

int getValue() { int value = -1; while (port.available() >= 3) { if (port.read() == 0xff) { value = (port.read() << 8) | (port.read()); } } return value; }

void pushValue(int value) { for (int i=0; i

void drawLines() { stroke(255); int displayWidth = (int) (width / zoom); int k = values.length - displayWidth; int x0 = 0; int y0 = getY(values[k]); for (int i=1; i

void drawGrid() { stroke(255, 0, 0); line(0, height/2, width, height/2); }

void keyReleased() { switch (key) { case '+': zoom *= 2.0f; println(zoom); if ( (int) (width / zoom) <= 1 ) zoom /= 2.0f; break; case '-': zoom /= 2.0f; if (zoom < 1.0f) zoom *= 2.0f; break; } }

void draw() { background(0); drawGrid(); val = getValue(); if (val != -1) { pushValue(val); } drawLines();

}

Comments

About This Instructable

445views

5favorites

License:

Bio: Eat*Sleep*Code Repeat
More by Prem67:Build a Proximity Sensor with the Linkit OneLinkit One Play MusicLinkit One Oscilloscope
Add instructable to: