Monthly Archives: April 2017

Arduino as an Oscilloscope

Yes an Arduino can be used as Oscilloscope without any additional hardware.

Burn this code to Arduino

const int probePin = A0;
 
void setup() {
  //Setup serial connection
  Serial.begin(9600); 
}
 
void loop() {
  //Read analog pin
  int val = analogRead(probePin);
 
  //Write analog value to serial port:
  Serial.write( 0xff ); //can be skipped                                                    
  Serial.write( (val >> 8) & 0xff ); //the higher 8 bits                                            
  Serial.write( val & 0xff ); //the lower 8 bits
}

Download Processing from https://processing.org/download/  This tool will be used to run a C code that will plot the graphs.

Now run this C code in Processing

/*
 * Oscilloscope
 * Gives a visual rendering of analog pin 0 in realtime.
 * 
 * This project is part of Accrochages
 * See http://accrochages.drone.ws
 * 
 * (c) 2008 Sofian Audry ([email protected])
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */ 
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<width-1; i++)
    values[i] = values[i+1];
  values[width-1] = value;
}

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<displayWidth; i++) {
    k++;
    int x1 = (int) (i * (width-1) / (displayWidth-1));
    int y1 = getY(values[k]);
    line(x0, y0, x1, y1);
    x0 = x1;
    y0 = y1;
  }
}

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();
}

This is not replacement for an actual oscilloscope. It is a simple one that can used to monitor signal levels and voltages.

Burning Arduino Bootloader to Atmega8 or other Atmega

This is for all who are having problems in burning the Arduino Bootloader on an Atmega8 or any other Atmega Processor using a Arduino Board like Arduino Uno.

  1. The processor for the first time burning will have to be used with an external oscillator. I was trying without the external oscillator (was depending on the internal oscillator -  setup the fuses also properly) and was banging my head. 
  2. The Arduino Uno (or any other board that you are using) will have to be burned with the ArduinoISP code. (Files -> Examples -> ArduinoISP -> ArduinoISP)
  3. Don't bother about the Chip Configurations (and/or binary) that are available on the net, especially if you are looking to use the external oscillator. None works properly.Find a board from the existing list that uses the same Processor. 
  4. For Atmega8 use the "Arduino NG or older" from the boards list. That board should also work for Atmega168
  5. If you are using a 8MHZ crystal then open the "boards.txt" files under "Program Files (x86)\Arduino\hardware\arduino\avr".  And edit the "atmegang.build.f_cpu". Change it to "8000000L".
  6. If you will be using the Internal Oscillator then you will have to change the fuse values to proper ones in the above board configuration.
  7. I had problems with high bitrate while burning. So I changed it to "9600" (atmegang.upload.speed=9600).
  8. After you are done with the configurations and connections use the option "Burn Bootloader" under Tools in the Arduino IDE

 

I also found tutorials where it was suggested to remove the processor from board (UNO board) which is being used as programmer. Don’t do that.

Putting the chip in an UNO board didn’t work for me. I don’t know why but it didn’t.

What I found is the Atmega8 works best with the external oscillator. With an internal oscillator I was having problems after running the chip continuously for quite some time.

 

The connections with an Arduino UNO
------------------                --------------------------
Arduino Uno                         Atmega 8 or other
------------------                --------------------------
10                                      Reset  (1 on Atmega8)
11                                      MOSI   (17 on Atmega8)
12                                      MISO   (18 on Atmega8)
13                                      SCLK   (19 on Atmega8)
And the AVCC pin should be externally connected to VCC, even if the ADC is not used.

 

And like many suggested on the Internet already, a standalone programmer is the best. I got a USBasp from eBay.

And I guess it is better to invest in a 328p processor due to limited resource of Atmega8 chip. More or less same price.

Atmega8 IC can be used as standalone IC, that is without using the whole Arduino board. Please see this article for details : Using Atmega8 or Atmega328p directly without using Arduino boards and Atmega8 to Arduino pin mapping

 

Eagle PCB Library for ESP8266 ESP-12

Eagle PCB Library for ESP-12

Please note though the library file is named as esp-12e, but it is for esp-12. The ESP-12E version will be published soon.

Somehow I couldn’t find a proper a library on the internet. I found only one but that had wrong pin spacing.

Download the esp-12e eagle library here

For more details on ESP-8266 visit this link

ESP8266 Hello World   ESP-8266 AT Commands  GPS Tracker using NEO 6M and ESP-12

 

Package
Symbol

 

Eagle PCB Library Atmega8 TQFP32

The Atmega8 TQFP32 package that is mostly available, for Eagle PCB, has the pins too thick to be handled in DIY or Homemade PCBs. The Atmega8-AI package in the attached library has been modified such that the pins are wide enough for proper placement/soldering of the chip and thin enough so that there is sufficient room between two adjacent pins while soldering the chip by hand.

Atmega8 TQFP32

 

 

Eagle Library for XC6210 LDO Voltage Regulator SOT-89-5 Package

XC6210 is a LDO Voltage regulator from Torex Semiconductor. It is available for various preset voltages starting from 0.80V to 5.00V at 0.05v increments. It is capable of delivering 700mA. The 3.3v version has typical drop of 70mV at 100mA. Here is the datasheet attached.

The chip is a bit delicate, I damaged two chips while soldering back after desoldering. And strangely in both cases the same pin broke.

The attached eagle library is for the SOT-89-5 package – XC6210 SOT-89-5 Eagle Library

Eagle PCB Library for MCP1826 SOT-223-5 Package

MCP1826 is a LDO Voltage Regulator from Microchip. Here is the datasheet attached. It comes in various packages. It comes in various configurations. The attached Eagle Library is for the SOT-223-5 package. That package has 6 pins including the tab and has “Chip Enable” and “Power Good” function. It is capable of delivering 1A. And at 1 amp the drop will be typically 250mV.

MCP1826 Eagle Library