基于Arduino的示波器V0.1 12864版
本帖最后由 迷你强 于 2013-8-15 09:32 编辑基于Arduino的示波器V0.1 12864版
可以接收0~5V的任意波形电压,将波形显示到12864液晶屏上。
关于示波器我就不多说了。
效果不错,不过波形复杂的话会有点闪,因为是串行连接。
先上图:
再上代码:
#include <U8glib.h>
U8GLIB_ST7920_128X64 u8g(3, 9, 8, U8G_PIN_NONE);
#define AR_SIZE( a ) sizeof( a ) / sizeof( a )
const int Input = A0;
int x, y = 128;
int ax, ay = 128;
int Status;
void setup()
{
for ( int i = 0;i < 128;i++)
{
Status = 64;
}
}
void draw()
{
y = map(analogRead(Input),0,1023,63,6);
for(x = 0;x < 128;x++)
{
if (x < 127){Status = Status;}else{Status = y;}
u8g.drawPixel(x,Status);//话波形
if (ay != Status)
{
u8g.drawLine(x,ay,x,Status);
ax = x;ay = Status;
}
}
u8g.setFont(u8g_font_4x6);//写文字
u8g.drawStr(1,5,"APE Arduino Oscilloscope V0.1");
u8g.drawLine(25.6, 6, 25.6, 64); //画网格
u8g.drawLine(25.6*2, 6, 25.6*2, 64);
u8g.drawLine(25.6*3, 6, 25.6*3, 64);
u8g.drawLine(25.6*4, 6, 25.6*4, 64);
u8g.drawLine(25.6*5, 6, 25.6*5, 64);
u8g.drawLine(0, 35 - 15, 128, 35 - 15);
u8g.drawLine(0, 35, 128, 35);
u8g.drawLine(0, 35 + 15, 128, 35 + 15);
}
void loop()
{
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
}
麻烦帮添加一下注释!
嗯嗯,这个需要一个奇葩的库:
U8glib
下载地址
代码介绍
英文专业户专用…… #include <U8glib.h>
U8GLIB_ST7920_128X64 u8g(3, 9, 8, U8G_PIN_NONE);
#define AR_SIZE( a ) sizeof( a ) / sizeof( a )
const int Input = A0;
int x, y = 128;
int ax, ay = 128;
int Status;
void setup()
{
for ( int i = 0;i < 128;i++)
{
Status = 64;
}
}
void draw()
{
y = map(analogRead(Input),0,1023,63,6);
for(x = 0;x < 128;x++)
{
if (x < 127){Status = Status;}else{Status = y;}
u8g.drawPixel(x,Status);//话波形
if (ay != Status)
{
u8g.drawLine(x,ay,x,Status);
ax = x;ay = Status;
}
}
u8g.setFont(u8g_font_4x6);//写文字
u8g.drawStr(1,5,"APE Arduino Oscilloscope V0.1");
u8g.drawLine(25.6, 6, 25.6, 64); //画网格
u8g.drawLine(25.6*2, 6, 25.6*2, 64);
u8g.drawLine(25.6*3, 6, 25.6*3, 64);
u8g.drawLine(25.6*4, 6, 25.6*4, 64);
u8g.drawLine(25.6*5, 6, 25.6*5, 64);
u8g.drawLine(0, 35 - 15, 128, 35 - 15);
u8g.drawLine(0, 35, 128, 35);
u8g.drawLine(0, 35 + 15, 128, 35 + 15);
}
void loop()
{
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
} 果然是个奇葩库!! 非常感兴趣,接线图也放一下吧! 我是来看奇葩库的,适当增加点外围元件可以拓展测量范围吧~~
先放Mulitisim的图 Fritizng连线图:
shenhaiyu 发表于 2012-11-24 16:39 static/image/common/back.gif
我是来看奇葩库的,适当增加点外围元件可以拓展测量范围吧~~
我本来想用运放加衰减的,后来感觉太麻烦了,就没做 亲,为什么我使用这个库却是花屏?!!无论是examples还是你的程序,就隐约有点形状,花屏很厉害。。
PS,我用的是并口传输,U8GLIB_ST7920_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, U8G_PIN_NONE, U8G_PIN_NONE, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16 :funk:这个u8g库的确很变态! zhi_jian 发表于 2012-12-26 20:21 static/image/common/back.gif
亲,为什么我使用这个库却是花屏?!!无论是examples还是你的程序,就隐约有点形状,花屏很厉害。。
PS, ...
我也遇到过,一般是线没有接好 zhi_jian 发表于 2012-12-26 20:21 static/image/common/back.gif
亲,为什么我使用这个库却是花屏?!!无论是examples还是你的程序,就隐约有点形状,花屏很厉害。。
PS, ...
我也遇到过,是线没接好 这也太酷吧! 您好请问您是用哪个版本的IDE啊
???
您好 经用你的代码显示的基线不是在50%处您的也是吗?