Skip to main content

Arduino Oscilloscope

Here I'm creating a cheap and straightforward oscilloscope using arduino+ Processing IDE, basically, here Arduino receives the data from the analog pins and converts into 8-bit data (1 byte ) and send through the serial port, The information is collected by the processing IDE according to the data the oscilloscope plot the waveform.

For transmitting and receiving data properly and synced a technique is used its called Handshake method my program is based on the SerialCallResponse program.
Click  to see the program
Serial Call and Response program
Here I explain how it is works 
  • First Arduino tries to  communicate with processing IDE
  • By sending A continuously through the serial port




  • Here we can see that in the serial monitor


  • If the processing receive A  it will clear the serial port of the processing
  • Then it will send the character A to the Arduino  
  • It is called the handshaking method
  • if the first contact is established then data(1 byte) will send at a time through the serial port



  • Here I'm sending the data by a delimiter  (samples the data) 
  • I designed my oscilloscope for measure up to 4 channels, but now I'm using it for only 2 channels, that's why I've to sample the data
  • The data will send one at a time if I've 4 data it will send one after one with a small duration of time
  • Ok now we discuss our above diagram
  • Once the initial contact is successful the Arduino sends the data by sample
  • If the data is received by the processing IDE, it will clear its port 
  • And send the character A to the Arduino
  • Again Arduino sends the value 
  • The processes are repeated as a loop

Now I explain the code

Arduino code

  1. int a = 0;    // First Channel
  2. int b = 0;   // Second Channel 
These code initial the 2 channel a & b
     3. int inByte = 0;         // incoming serial byte
It will store the value( character A ) from the processing IDE
    4.  void setup() {
    5. // start serial port at 9600 bps:
    6. Serial.begin(9600);
    7.  while (!Serial) {
    8.  ; // wait for serial port to connect. Needed for native USB port only
    9. }

Basically, it initializes the serial port baud rate and the 7th line meaning is, When you open the serial port of a board like the Uno or Mega the whole board usually resets*, so opening the serial port allows you to see the first bits of the serial data. On the Leonardo etc it doesn't reset when you open the serial, so any serial output during the setup() function would be missed. Adding that line makes the board pause until you open the serial port, so you get to see that initial bit of data.
   10. establishContact();  // send a byte to establish contact until receiver responds

It is a user-defined function. The function will be declared under the loop section 
   11. } void loop() {
   12. // if we get a valid byte, read analog ins:
   13. if (Serial.available() > 0) {
   14.  // get incoming byte:
   15. inByte = Serial.read();


These lines are continuously checking the acknowledgment from the Processing and read the serial data and store it on inByte

   16. a = analogRead(A0)/4 ;// 1024/4 =255
   17. b = analogRead(A1)/4;
   18.  delay(10);

These  lines  are used to get the analog values from the A0 and A1 pins and it converted into 8 bit by dividing the value by 4 
  19. Serial.write(a);
  20. Serial.write(b);
  21. }
  22. }

Write the values to the serial port, one value at a time
  23. void establishContact() {
  24. while (Serial.available() <= 0) {
  25.  Serial.print('A');   // send a capital A
  26. delay(300);
  27. }
  28. }

These lines are the user-defined function, It basically do the initial contact with the processing IDE by sending the character  A

Comments

Popular posts from this blog

ATMEGA328P-TQFP32-PINOUT

Here'a a pinout diagram I created for the ATMEGA328P TQFP32 . It is shared under CC-BY-SA license. You're free to modify it and share. Just give a backlink to my project website if possible (I have not posted the pinout diagram on my website yet. I'm also attaching a PDF,SVG version so that you can edit with any vector editing software. If you want me to create pinout diagrams for other boards, I'd be happy spend some free time on it. Let me know. Hope you'll find it useful :)  Github: https://github.com/Krishnawa/ATMEGA328P-TQFP32-PINOUT

Arduino-Register Programming

Simple LED Blink Program Here I'm explained my first register level coding, It is awesome and it's make me much more understand about how the microcontroller is working, I'm still learning, so here I'm sharing what I understood. Are you ready for this then let's go Arduino language Blink program This is simple Blink program without using any functions!. Take a look at the code the same code is converting to register level unsigned long counter = 0 ; // initializing  counter variable and set to 0 void setup ( ) {   pinMode ( LED_BUILTIN , OUTPUT ) ; // set 13th pin LED as output   Serial . begin ( 9600 ) ; // initializing Serial communications } void loop ( ) {   counter ++ ; //increment the counter   Serial . println ( counter ) ; // print the counter value on Serial monitor   if ( counter > 250 ) {     digitalWrite ( LED_BUILTIN , HIGH ) ; // if counter value greater than 250 then LED turn ON  ...

Bootloader - Arduino

What is a bootloader, and what is bootloading? The bootloader is the little program that runs when you turn the Arduino on, or press the reset button. Its main function is to wait for the Arduino software on your computer to send it a new program for the Arduino, which it then writes to the memory on the Arduino. This is important, because normally you need a special device to program the Arduino. The bootloader is what enables you to program the Arduino using just the USB cable. When we refer to "bootloading" the Arduino, we are talking about using a special device (called an In-System Programmer or ISP) to replace the bootloader software. Normally the default bootloader of arduino is Optiboot Here I am showing that an alternative and some more advanced options in Arduino bootloader option called MiniCore Why MiniCore? An Arduino core for the ATmega328, ATmega168, ATmega88, ATmega48 and ATmega8, all running a custom version of Optiboot for increased functio...