如何使用Bigfish扩展板
作者:机器谱
概述 输入输出端口 8×8Led点阵 |
· 完全兼容Arduino控制板标准接口
· 彩色分组插针,一目了然
· 全部铜制插针,用料考究,电器性能稳定
· 优秀PCB设计,美观大方
· 多种特殊接口设计,兼容所有探索者电子模块,使用方便
· 所有3P、4P接口采用防反插设计,避免电子模块间连线造成的误操作
· 板载舵机接口、直流电机驱动芯片、MAX7219LED驱动芯片,可直接驱动舵机、直流电机、数码管等机器人常规执行部件,无需外围电路
· 具有5V、3.3V及vin 3种电源接口,便于为各类扩展模块供电
· 4针防反插接口供电5V
· 舵机接口使用3A的稳压芯片LM1085ADJ,为舵机提供6v额定电压
· 8*8LED点阵模块采用MAX7219驱动芯片
· 板载两片直流电机驱动芯片L9170,支持3V~15V的vin电压,可驱动两个直流电机。
· 2个2*5的杜邦座扩展坞,方便无线模块、OLED、蓝牙等扩展模块直插连接,无需额外接线
D11\D12舵机端口与LED点阵复用,请注意避免同时使用。
背面两侧的跳线分别作用于两侧的红色接口(通常采用5V,接传感器)或白色接口(通常采用6V,接舵机),使用前请检查背面跳线设置是否与器件电压相符。
1.简介
Arduino是开源的控制板,非常适合爱好电子制作的朋友制作互动作品,但对于一些不熟悉电子技术的爱好者,要在Arduino控制板上添加电路是一个比较麻烦的事,所以我们设计了一个专用于简单机器人的扩展板——BigFish,能将大部分传感器轻松地和Arduino控制板连接。
通过BigFish扩展板连接的电路可靠稳定,上面还扩展了伺服电机接口、8*8Led点阵、直流电机驱动以及一个通用扩展接口,可以说是Arduino控制板的必备配件。
序号 | 内容 |
1 | Bigfish2.1电路图原理图等 |
2 | Basra&Bigfish检测程序源代码 |
7.资料下载
【整体打包】-【U007】如何使用Bigfish扩展板-1.概述-资料附件.zip | 1.97MB | 下载177次 | 下载 |
1. 传感器口- 数字量(Digital)输入
按下图示意将TTL型传感器连接到BigFish扩展板的红色传感器端口上。
打开“文件-示例-02.Digital-Button”,弹出Button例程窗口
/* Button
Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2.
The circuit: - LED attached from pin 13 to ground through 220 ohm resistor - pushbutton attached to pin 2 from +5V - 10K resistor attached to pin 2 from ground
- Note: on most Arduinos there is already an LED on the board attached to pin 13.
created 2005 by DojoDave <http://www.0j0.org> modified 30 Aug 2011 by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button */
// constants won't change. They're used here to set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin
// variables will change: int buttonState = 0; // variable for reading the pushbutton status
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } |
上述例程默认代码中,第一行const int buttonPin = 2语句,参数2表示传感器安装在D2端口。而实际上,我们将传感器连在了BigFish的左上接口。这个左上接口的端口号为A0和A1。而所有的探索者TTL触发型传感器都使用的紧挨VCC的引脚作为信号端口,因此,BigFish的这个接口的端口号应为A0。修改第一行代码为:const int buttonPin = A0 。
在buttonState = digitalRead(buttonPin)语句中,digitalRead表示读取端口的电平状态,如果是高电平则返回HIGH,如果是低电平则返回LOW。而所有的探索者TTL触发型传感器在非触发状态时端口电平为HIGH,触发状态时端口电平为LOW。因此这个语句表示,传感器没有触发时LED指示灯常亮,触发时熄灭。
修改buttonPin的参数后,将程序上传到控制板中,观察Basra控制板上D13 Led灯的随传感器的触发状态的变化。
2. 传感器口 - 模拟量(Analog )输入
按下图示意将一个可以读取模拟量的传感器,如摇杆模块,连接到BigFish扩展板的传感器端口上。
打开“文件→示例→03.Analog→AnalogInOutSerial”,弹出例程窗口
/* Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255 and uses the result to set the pulse width modulation (PWM) of an output pin. Also prints the results to the Serial Monitor.
The circuit: - potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground - LED connected from digital pin 9 to ground through 220 ohm resistor
created 29 Dec. 2008 modified 9 Apr 2012 by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial */
// These constants won't change. They're used to give names to the pins used: const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out)
void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }
void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue);
// print the results to the Serial Monitor: Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue);
// wait 2 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(2); } |
将程序上传到控制板中,打开串口监视器,左右摇动摇杆,观察显示的内容,如下图所示:
可以再试着将一个直流电机连接到D9/D10的直流电机接口,观察电机的转动速度和摇杆位置的关系。
3. Motor - 直流电机接口
按下图示意将直流电机连接到BigFish扩展板的直流电机接口上。
打开“文件→示例→03.Analog→Fading”,弹出例程窗口
/* Fading
This example shows how to fade an LED using the analogWrite() function.
The circuit: - LED attached from digital pin 9 to ground through 220 ohm resistor.
created 1 Nov 2008 by David A. Mellis modified 30 Aug 2011 by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fading */
int ledPin = 9; // LED connected to digital pin 9
void setup() { // nothing happens in setup }
void loop() { // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); }
// fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } |
这个例程的内容是控制连接在D9端口的LED实现一个呼吸灯的效果,原理是通过analogWrite语句给D9赋予不同的电压输出值来实现。这个原理和控制电机调速完全一样。
将程序uploading到控制板中,观察电机的转动速度的变化。
更多关于驱动直流电机的知识,请参考:【U001】如何驱动直流有刷电机(https://www.robotway.com/col.jsp?id=119)。
4. Servo - 舵机接口
按下图示意将舵机连接到BigFish扩展板的舵机接口上,注意舵机连接线的黑线与GND端口相连。
打开“File→Examples→Servo→Sweep”,弹出例程窗口,将舵机端口从9修改为4。将程序上传到控制板中,观察舵机的转动变化。
/* Sweep by BARRAGAN <http://barraganstudio.com> This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep */ #include <Servo.h> Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15 ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15 ms for the servo to reach the position } } |
更多关于驱动舵机的知识,请参考:【U002】如何驱动模拟舵机。
1. 安装LED扩展库
只要安装了LED扩展库,就可以很方便的编程控制8×8LED点阵了。
将LED扩展库..\8×8LED点阵扩展库\libraries\LedControl拷贝到Arduino的libraries中。启动Arduino IDE, 可以发现,在示例中增加了LedControl的例程,打开“文件→示例→LedControl→LCDemoMatrix”,将例程上传到控制板中,观察Led点阵上显示的内容,理解它们和代码的对应关系。
#include "LedControl.h" /* Now we need a LedControl to work with. ***** These pin numbers will probably not work with your hardware ***** pin 12 is connected to the DataIn pin 11 is connected to the CLK pin 10 is connected to LOAD We have only a single MAX72XX. */ LedControl lc=LedControl(12,11,13,1); /* we always wait a bit between updates of the display */ unsigned long delaytime=100; unsigned long delaytime1=2000; void setup() { /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ lc.shutdown(0,false); /* Set the brightness to a medium values */ lc.setIntensity(0,8); /* and clear the display */ lc.clearDisplay(0); } /* This method will display the characters for the word "Arduino" one after the other on the matrix. (you need at least 5x7 leds to see the whole chars) */ void value_8(byte value []) { for(int i=0;i<8;i++) { lc.setRow(0,i,value[i]); } } void writeArduinoOnMatrix() { /* here is the data for the characters */ byte a[8]={0x18,0x24,0x66,0x66,0x7E,0x66,0x66,0x66}; byte r[8]={0x60,0x63,0x66,0x6C,0x78,0x70,0x60,0x60}; byte d[8]={0x78,0x7C,0x66,0x66,0x66,0x66,0x7C,0x78}; byte u[8]={0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x3C}; byte i[8]={0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x18}; byte n[8]={0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66}; byte o[8]={0x3C,0x7E,0xC3,0xC3,0xC3,0xC3,0x7E,0x3C}; /* now display them one by one with a small delay */ value_8(a); delay(delaytime1); lc.clearDisplay(0); value_8(r); delay(delaytime1); lc.clearDisplay(0); value_8(d); delay(delaytime1); lc.clearDisplay(0); value_8(u); delay(delaytime1); lc.clearDisplay(0); value_8(i); delay(delaytime1); lc.clearDisplay(0); value_8(n); delay(delaytime1); lc.clearDisplay(0); value_8(o); delay(delaytime1); lc.clearDisplay(0); lc.setRow(0,0,0); lc.setRow(0,1,0); lc.setRow(0,2,0); lc.setRow(0,3,0); lc.setRow(0,4,0); delay(delaytime); } /* This function lights up a some Leds in a row. The pattern will be repeated on every row. The pattern will blink along with the row-number. row number 4 (index==3) will blink 4 times etc. */ void rows() { for(int row=0;row<8;row++) { delay(delaytime); lc.setRow(0,row,B10100000); delay(delaytime); lc.setRow(0,row,(byte)0); for(int i=0;i<row;i++) { delay(delaytime); lc.setRow(0,row,B10100000); delay(delaytime); lc.setRow(0,row,(byte)0); } } } /* This function lights up a some Leds in a column. The pattern will be repeated on every column. The pattern will blink along with the column-number. column number 4 (index==3) will blink 4 times etc. */ void columns() { for(int col=0;col<8;col++) { delay(delaytime); lc.setColumn(0,col,B10100000); delay(delaytime); lc.setColumn(0,col,(byte)0); for(int i=0;i<col;i++) { delay(delaytime); lc.setColumn(0,col,B10100000); delay(delaytime); lc.setColumn(0,col,(byte)0); } } } /* This function will light up every Led on the matrix. The led will blink along with the row-number. row number 4 (index==3) will blink 4 times etc. */ void single() { for(int row=0;row<8;row++) { for(int col=0;col<8;col++) { delay(delaytime); lc.setLed(0,row,col,true); delay(delaytime); for(int i=0;i<col;i++) { lc.setLed(0,row,col,false); delay(delaytime); lc.setLed(0,row,col,true); delay(delaytime); } } } } void loop() { writeArduinoOnMatrix(); rows(); columns(); single(); } |
这个例程的效果如下列动图所示:
2. 显示笑脸
这段代码将会在点阵上显示一个笑脸。
我们可以利用字库软件模拟出需要亮/灭的点,自动生成LED阵列对应的ASM二进制编码,写到代码里。
将显示笑脸的例程smile.ino上传到控制板。
#include "LedControl.h" LedControl lc=LedControl(12,11,13,1); void setup() { lc.shutdown(0,false); lc.setIntensity(0,8); lc.clearDisplay(0); lc.setRow(0,0,0xff); lc.setRow(0,1,B10000001); lc.setRow(0,2,B10100101); lc.setRow(0,3,B10000001); lc.setRow(0,4,B11000011); lc.setRow(0,5,B10100101); lc.setRow(0,6,B10011001); lc.setRow(0,7,0xff); } void loop() { } |
显示效果如下:
使用熟练后,我们甚至可以使用点阵做动画,或者配合按钮、摇杆等模块制作小游戏。
3. 资料清单
序号 | 内容 |
1 | 点阵原理图 |
2 | 函数库 |
3 | 例程 |
4 | 字库软件 |
【整体打包】-【U007】如何使用Bigfish扩展板-8×8LED点阵-资料附件.zip | 311.97KB | 下载22次 | 下载 |
|