Un oscilloscope arduino

Un oscilloscope c'est 150 euros pour des bouzins numériques, et plus de 400 euros pour des appareils corrects.Avec un arduino , ça va prendre 5 min pour créer un oscilloscope très basique qui sera efficace pour du dépannage occasionnel, sans avoir besoin d'une grande précision, et pour des circuits électroniques qui ne montent pas au delà de 5V (c'est généralement le cas pour les montages arduino).

Il existe le projet arduinoscope. Qui fonctionne avec java et surtout: Je n'aime pas Java, et la réciproque est vraie. Je n'ai pas insisté pour comprendre comment le faire marcher. Du coup, je vais vous parler ici de lxardoscope

Ça fonctionne de cette marnière:

  • l'arduino mesure en permanence la tension sur A0 A1 etc...
  • l'arduino envoie ses mesures sur le serial
  • Le programme lxardoscope lit les données série pour afficher un oscillo.

Installation

wget downloads.sourceforge.net/project/lxardoscope/lxardoscope_0.95/lxardoscope_0.95.tar.gz
tar -zxvf lxardoscope_0.95.tar.gz
cd lxardoscope_0.95/
#on peut compiler, mais on peut aussi tout simplement copier l'éxécutable
#en tant qu'user root
cp lxardoscope /usr/local/sbin
#à présent la commande pour démarrer l'oscillo est:
lxardoscope

Installation du code sur l'arduino

Le code arduino est très simple. Vous le trouverez dans le fichier lxardoscope_0.95/ATmega/lxardoscope95/lxardoscope95.ino

Cependant, Oskar Leuthold, l'auteur de ce code, a prévu que vous appliqueriez une tension de référence sur la pin AREF de l'arduino. Vous pouvez faire en sorte de ne pas en avoir besoin en commentant la ligneanalogReference(EXTERNAL); comme ci dessous, ligne 56. La référence sera alors 5V.

/*
 *
 * This file is part of the LXARDOSCOPE package.
 *
 * LXARDOSCOPE is an Arduino based oscilloscope for Linux, using the Xforms library.
 *
 * Copyright (C) 2013 Oskar Leuthold
 * 
 * LXARDOSCOPE 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.
 *
 * LXARDOSCOPE 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with LXARDOSCOPE; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */
 
//   This program for Arduino Uno reads two channels and sends the data
//   out through the serial port in 4 bytes.
//   For synchronization purposes, the following scheme was chosen:
//   A0 data:   A09 (MSB) A08 A07 A06 A05 A04 A03 A02 A01 A00 (LSB)
//   A1 data:   A19 (MSB) A18 A17 A16 A15 A14 A13 A12 A11 A10 (LSB)
//   sent as byte 1:   1 1 1 A09 A08 A07 A06 A05
//       and byte 2:   0 1 1 A04 A03 A02 A01 A00
//       and byte 3:   0 1 1 A19 A18 A17 A16 A15
//       and byte 4:   0 1 1 A14 A13 A12 A11 A10
//
//    (This arrangement was chosen for hystorical reasons; there are
//     many other possibilities. 3 bytes would be enough, but this could
//     possibly create a nonsymmetry between the channels.
//
//
int sensorValue = 0;        // value read from the pot
byte lb;
byte hb;
boolean ac1=false;		// Channel 1 AC amplifier off
boolean ac2=false;		// Channel 2 AC amplifier off

void setup() {
  // initialize serial communications at 115200 bps:
  Serial.begin(115200);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  //analogReference(EXTERNAL);
}

void loop() {
//  if(transmit) {
      digitalWrite(8,HIGH);
	  if(ac1) sensorValue = analogRead(A2);
	  else  sensorValue = analogRead(A0);           
//        sensorValue = test;
// shift sample by 3 bits, and select higher byte  
      hb=highByte(sensorValue<<3); 
// set 3 most significant bits and send out
      Serial.write(hb|224); 
// select lower byte and clear 3 most significant bits
      lb=(lowByte(sensorValue))&31;
// set bits 5 and 6 and send out
      Serial.write(lb|96);
//
      digitalWrite(8,LOW); 
		if(ac2) sensorValue = analogRead(A3);
		else sensorValue = analogRead(A1);
//      sensorValue = 200;
// shift sample by 3 bits, and select higher byte 
      hb=highByte(sensorValue<<3); 
// set bits 5 and 6 and send out
      Serial.write(hb|96); 
// select lower byte and clear 3 most significant bits
      lb=(lowByte(sensorValue))&31;
// set bits 5 and 6 and send out
      Serial.write(lb|96);
//      }
      if(Serial.available()) {
		char inChar = (char)Serial.read();
		if (inChar == '1') {            // cal channel 1
			digitalWrite(9, HIGH);      // gnd1
			digitalWrite(11, LOW);      // AC1 off
			ac1=false;
		}
		else if (inChar == '2') {     // channel 1 DC & AC, low gain
            digitalWrite(9, LOW);      // gnd1
			digitalWrite(11, LOW);    // AC1 off
			ac1=false;
		}
		else if (inChar == '3') {     // channel 1 use AC amplifier
            digitalWrite(9, LOW);      // gnd1
			digitalWrite(11, HIGH);    // AC1 on
			ac1=true;
		}
		else if (inChar == '4') {      // cal channel 2
            digitalWrite(10, HIGH);     // gnd2
			digitalWrite(12, LOW);      // AC2 off
			ac2=false;
		}
		else if (inChar == '5') {      // channel 2 DC & AC, low gain
            digitalWrite(10, LOW);     // gnd2
			digitalWrite(12, LOW);     // AC2 off
			ac2=false;
		}
		else if (inChar == '6') {      // channel 2 use AC amplifier
			digitalWrite(10, LOW);       // gnd2
            digitalWrite(12, HIGH);      // AC2 on
			ac2=true;
		}
        else if (inChar == '*') {
                digitalWrite(13, HIGH);      // LED (on)
        }
        else if (inChar == '#') {
                digitalWrite(13, LOW);      // LED (off)
        }                
		}
 }

Utilisation.

Une fois votre arduino programmé:

  • Reliez A0 et A1 aux point de mesure de l'oscillation
  • Branchez l'arduino et démarrez lxardoscope.
  • En bas à droite, précisez /dev/ttyACM0 (ou ttyACM1, le truc qui correspond à l'USB quoi )
  • "Start"

IMG_20140219_225413.jpg

Limites et améliorations possibles.

ça me parait un peu imprécis quand même et l'échantillonage des mesures est limité pas les capacités de l'arduino, au delà de quelques khz c'est tres aléatoire. Dans le tar.gz du programe, vous trouverez quelques documentations sur la façon de préparer un port com, ou de permettre des mesures de tensions plus élevées.

Sinon, il existe un shield (non testé) pour améliorer les capacité de votre oscilloscope.

Peut etre que dans cette version de l'ossilo me suffira pour continuer le projet de télémètres ultrason et RF.

Page top