2013年春季《电子设计竞赛》课程之arduino智能小车实训
3 posters
2013年春季《电子设计竞赛》课程之arduino智能小车实训
愿意购买安装的人数在1/3~1/2比较合理。
不愿意训练动手实践能力的,家庭经济困难的,建议不要购买。
12:08:14
购买:
(1)螃蟹王国 橡胶车轮 玩具 43MM车轮 D字口 3MM 工程比赛 模型配件
http://item.taobao.com/item.htm?spm=a1z10.3.w17-394128395.44.UG3O70&id=13940645051&
(2)螃蟹王国 25mm电机固定架 直流减速电机支架 模型车支架 工程大赛
http://item.taobao.com/item.htm?spm=a1z10.3.w17-394128395.19.Py3KI5&id=14944201785&
(3)【三美】码盘测速电机 测速减速电机 测速码盘编码器 334线AB相
http://item.taobao.com/item.htm?spm=2013.1.1000774.16.kK3QNK&id=17712482310
2013-5-8 19:32:34
http://item.taobao.com/item.htm?spm=a230r.1.14.69.XHwgy6&id=10007853785
王冠 2013-5-8 18:10:47
老师!在不?
王冠 2013-5-8 19:35:50
这家的神火18650 我和他讲价讲到了14.5一只!每对送座充一个 装电池的盒子一个! 给他说的是要买30到40对电池
王冠 2013-5-8 19:53:47
http://item.taobao.com/item.htm?spm=a230r.1.14.69.q3u1y2&id=12486140274
这家电池盒2.5元,可以发顺丰
不愿意训练动手实践能力的,家庭经济困难的,建议不要购买。
12:08:14
购买:
(1)螃蟹王国 橡胶车轮 玩具 43MM车轮 D字口 3MM 工程比赛 模型配件
http://item.taobao.com/item.htm?spm=a1z10.3.w17-394128395.44.UG3O70&id=13940645051&
(2)螃蟹王国 25mm电机固定架 直流减速电机支架 模型车支架 工程大赛
http://item.taobao.com/item.htm?spm=a1z10.3.w17-394128395.19.Py3KI5&id=14944201785&
(3)【三美】码盘测速电机 测速减速电机 测速码盘编码器 334线AB相
http://item.taobao.com/item.htm?spm=2013.1.1000774.16.kK3QNK&id=17712482310
2013-5-8 19:32:34
http://item.taobao.com/item.htm?spm=a230r.1.14.69.XHwgy6&id=10007853785
王冠 2013-5-8 18:10:47
老师!在不?
王冠 2013-5-8 19:35:50
这家的神火18650 我和他讲价讲到了14.5一只!每对送座充一个 装电池的盒子一个! 给他说的是要买30到40对电池
王冠 2013-5-8 19:53:47
http://item.taobao.com/item.htm?spm=a230r.1.14.69.q3u1y2&id=12486140274
这家电池盒2.5元,可以发顺丰
由Admin于周六 六月 08, 2013 10:21 pm进行了最后一次编辑,总共编辑了2次
智能小车 交流论坛
amoBBS 阿莫电子论坛»论坛首页 › 机械电子› 智能小车
http://www.amobbs.com/forum-3032-1.html
其中一名留学生的作品,值得我们学习,一份完整的平衡车制作文档 [uC-OS II, Virtual COM,MFC C++, OpenGL] ,见
http://www.amobbs.com/thread-5480603-1-2.html
http://www.amobbs.com/forum-3032-1.html
其中一名留学生的作品,值得我们学习,一份完整的平衡车制作文档 [uC-OS II, Virtual COM,MFC C++, OpenGL] ,见
http://www.amobbs.com/thread-5480603-1-2.html
由Admin于周三 五月 08, 2013 11:31 pm进行了最后一次编辑,总共编辑了1次
Arduino PID
http://blog.sina.com.cn/s/blog_69bcf45201019bnd.html
原文链接:http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/
原文链接:http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/
18650锂电池 3.7v锂电池大容量
18650锂电池 3.7v锂电池大容量 迈思路正品充电 手电电池
http://detail.tmall.com/item.htm?spm=a230r.1.14.159.8BH7cE&id=20637964030
德力普正品 18650强光手电可充电锂电池 2800毫安 尖头 10.5元/粒
http://item.taobao.com/item.htm?spm=a1z10.3.w1017-1581313677.15.rhkWPk&id=10049320304&
http://detail.tmall.com/item.htm?spm=a230r.1.14.159.8BH7cE&id=20637964030
德力普正品 18650强光手电可充电锂电池 2800毫安 尖头 10.5元/粒
http://item.taobao.com/item.htm?spm=a1z10.3.w1017-1581313677.15.rhkWPk&id=10049320304&
Arduino UNO R3 & L298P Arduino Motor Shield
Arduino UNO R3(Cduino,2012新版)
http://item.taobao.com/item.htm?spm=a1z10.1.w4-17695906509.4.wID1mQ&id=16637489635
L298P Arduino Motor Shield 直流、步进电机驱动模块 Cduino
http://item.taobao.com/item.htm?spm=2013.1.0.103.NOzACP&scm=1007.77.3.0&id=18125367850&pvid=915d3c73-71fe-4fd3-81c6-e2d07d6e2a43&ad_id=&am_id=&cm_id=&pm_id=
http://item.taobao.com/item.htm?spm=a1z10.1.w4-17695906509.4.wID1mQ&id=16637489635
L298P Arduino Motor Shield 直流、步进电机驱动模块 Cduino
http://item.taobao.com/item.htm?spm=2013.1.0.103.NOzACP&scm=1007.77.3.0&id=18125367850&pvid=915d3c73-71fe-4fd3-81c6-e2d07d6e2a43&ad_id=&am_id=&cm_id=&pm_id=
程序1
//CDUINO MOTOR SHIELD + UNO 20130510
//test for forward/backward/left/right
int N1=12;
int PWM1=3;
int N2=13;
int PWM2=11;
void setup()
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(N1,HIGH);
digitalWrite(PWM1,HIGH);
digitalWrite(N2,HIGH);
digitalWrite(PWM2,HIGH);
}
//test for forward/backward/left/right
int N1=12;
int PWM1=3;
int N2=13;
int PWM2=11;
void setup()
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(N1,HIGH);
digitalWrite(PWM1,HIGH);
digitalWrite(N2,HIGH);
digitalWrite(PWM2,HIGH);
}
由Admin于周四 六月 06, 2013 10:14 am进行了最后一次编辑,总共编辑了1次
程序2
//CDUINO MOTOR SHIELD + UNO 20130510
//speed regulation use PWM
int N1=12;
int PWM1=3;
int N2=13;
int PWM2=11;
void setup()
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(N1,HIGH);
analogWrite(PWM1,100);
digitalWrite(N2,HIGH);
analogWrite(PWM2,100);
}
//speed regulation use PWM
int N1=12;
int PWM1=3;
int N2=13;
int PWM2=11;
void setup()
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(N1,HIGH);
analogWrite(PWM1,100);
digitalWrite(N2,HIGH);
analogWrite(PWM2,100);
}
由Admin于周四 六月 06, 2013 10:14 am进行了最后一次编辑,总共编辑了1次
程序3
//pass at UNO + HC SR04, COM(serial) OUT,20130602
int inputPin=6; // 定义超声波信号接收接口, ECHO 接6口
int outputPin=5; // 定义超声波信号发出接口, TRIG 接5口
void setup()
{
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
void loop()
{
digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
delayMicroseconds(2);
digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
delayMicroseconds(10);
digitalWrite(outputPin, LOW); // 保持发出超声波信号接口低电平
int distance = pulseIn(inputPin, HIGH); // 读出脉冲时间
distance= distance/58; // 将脉冲时间转化为距离(单位:厘米)
Serial.print("distance = " ); //输出距离值
Serial.print(distance ); //输出距离值
Serial.println(" cm" ); //输出距离值
delay(50);
}
/*
http://www.arduino123.com/a/jiaocheng/gaoji/2012/0927/311.html
HC-SR04 超声波测距模块可提供2cm-400cm的非接触式距离测量功能,测距精度可达3mm,模块包括超声波发射器、接受器与控制电路。
基本工作原理:
(1)采用IO口TRIG触发测距,给至少10us的高电平信号;
(2)模块自动发送8个40khz的方波,自动检测是否有信号返回;
(3)有信号返回,通过IO口ECHO输出一个高电平,高电平持续时间就是超声波从发射到返回的时间。
公式:us/58=厘米 或者 us/148=英寸;或是:测试距离=(高电平时间*声速(340/S))/2;
建议测量周期为60ms以上,以防止发射信号对回响信号的影响。被测物体面积不小于0.5平方米。
超声波模块SR04与Arduino连接:
TRIG 接Digital 5口,触发测距;ECHO接Digital 4口,接收距离信号。
*/
int inputPin=6; // 定义超声波信号接收接口, ECHO 接6口
int outputPin=5; // 定义超声波信号发出接口, TRIG 接5口
void setup()
{
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
void loop()
{
digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
delayMicroseconds(2);
digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
delayMicroseconds(10);
digitalWrite(outputPin, LOW); // 保持发出超声波信号接口低电平
int distance = pulseIn(inputPin, HIGH); // 读出脉冲时间
distance= distance/58; // 将脉冲时间转化为距离(单位:厘米)
Serial.print("distance = " ); //输出距离值
Serial.print(distance ); //输出距离值
Serial.println(" cm" ); //输出距离值
delay(50);
}
/*
http://www.arduino123.com/a/jiaocheng/gaoji/2012/0927/311.html
HC-SR04 超声波测距模块可提供2cm-400cm的非接触式距离测量功能,测距精度可达3mm,模块包括超声波发射器、接受器与控制电路。
基本工作原理:
(1)采用IO口TRIG触发测距,给至少10us的高电平信号;
(2)模块自动发送8个40khz的方波,自动检测是否有信号返回;
(3)有信号返回,通过IO口ECHO输出一个高电平,高电平持续时间就是超声波从发射到返回的时间。
公式:us/58=厘米 或者 us/148=英寸;或是:测试距离=(高电平时间*声速(340/S))/2;
建议测量周期为60ms以上,以防止发射信号对回响信号的影响。被测物体面积不小于0.5平方米。
超声波模块SR04与Arduino连接:
TRIG 接Digital 5口,触发测距;ECHO接Digital 4口,接收距离信号。
*/
程序4
//PASS OK AT UNO+L298,20130518,23:18
#define DEBUG 0 // set to 1 to print to serial monitor, 0 to disable
#include <Servo.h>
Servo headservo; // 头部舵机对象
// Constants
const int EchoPin = 6; //超声波信号输入
const int TrigPin = 5; //超声波控制信号输出
const int leftmotorpin1 = 12; // 直流电机信号输出
const int leftmotorpin2 = 3;
const int rightmotorpin1 = 13;
const int rightmotorpin2 = 11;
const int HeadServopin = 2; // 舵机信号输出 只有9或10接口可利用
const int Sharppin = 3; // 红外输入
const int maxStart = 800; //run dec time
// Variables
int isStart = maxStart; //启动
int currDist = 0; // 距离
boolean running = false;
void setup() {
Serial.begin(9600); // 开始串行监测
//信号输入接口
pinMode(EchoPin, INPUT);
pinMode(TrigPin, OUTPUT);
pinMode(Sharppin, INPUT);
pinMode(HeadServopin, OUTPUT);
pinMode(leftmotorpin1, OUTPUT);
pinMode(leftmotorpin2, OUTPUT);
pinMode(rightmotorpin1, OUTPUT);
pinMode(rightmotorpin1, OUTPUT);
//信号输出接口
//for (int pinindex = 3; pinindex < 11; pinindex++) {
// pinMode(pinindex, OUTPUT); // set pins 3 to 10 as outputs
//}
//舵机接口
headservo.attach(HeadServopin);
//启动缓冲活动头部
headservo.write(70);
delay(2000);
headservo.write(20);
delay(2000);
}
void loop() {
if(DEBUG){
Serial.print("running:");
if(running){
Serial.println("true");
}
else{
Serial.println("false");
}
}
if (isStart <= 0) {
if(running){
totalhalt(); // stop!
}
int findsomebody = digitalRead(Sharppin);
if(DEBUG){
Serial.print("findsomebody:");
Serial.println(findsomebody);
}
if(findsomebody > 0) {
isStart = maxStart;
}
delay(4000);
return;
}
isStart--;
delay(100);
if(DEBUG){
Serial.print("isStart: ");
Serial.println(isStart);
}
currDist = MeasuringDistance(); //读取前端距离
if(DEBUG){
Serial.print("Current Distance: ");
Serial.println(currDist);
}
if(currDist > 30) {
nodanger();
}
else if(currDist < 15){
backup();
randTrun();
}
else {
//whichway();
randTrun();
}
}
//测量距离 单位厘米
long MeasuringDistance() {
long duration;
//pinMode(TrigPin, OUTPUT);
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(5);
digitalWrite(TrigPin, LOW);
//pinMode(EchoPin, INPUT);
duration = pulseIn(EchoPin, HIGH);
return duration / 29 / 2;
}
// 前进
void nodanger() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
return;
}
//后退
void backup() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
delay(1000);
}
//选择路线
void whichway() {
running = true;
totalhalt(); // first stop!
headservo.write(20);
delay(1000);
int lDist = MeasuringDistance(); // check left distance
totalhalt(); // 恢复探测头
headservo.write(120); // turn the servo right
delay(1000);
int rDist = MeasuringDistance(); // check right distance
totalhalt(); // 恢复探测头
if(lDist < rDist) {
body_lturn();
}
else{
body_rturn();
}
return;
}
//重新机械调整到初始状态
void totalhalt() {
digitalWrite(leftmotorpin1, HIGH);
analogWrite(leftmotorpin2, 20);
digitalWrite(rightmotorpin1, HIGH);
analogWrite(rightmotorpin2, 20);
headservo.write(70); // set servo to face forward
running = false;
return;
delay(1000);
}
//左转
void body_lturn() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, HIGH);
analogWrite(rightmotorpin2, 100);
delay(1500);
totalhalt();
}
//右转
void body_rturn() {
running = true;
digitalWrite(leftmotorpin1, HIGH);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
delay(1500);
totalhalt();
}
void randTrun(){
long randNumber;
randomSeed(analogRead(0));
randNumber = random(0, 10);
if(randNumber > 5) {
body_rturn();
}
else
{
body_lturn();
}
}
#define DEBUG 0 // set to 1 to print to serial monitor, 0 to disable
#include <Servo.h>
Servo headservo; // 头部舵机对象
// Constants
const int EchoPin = 6; //超声波信号输入
const int TrigPin = 5; //超声波控制信号输出
const int leftmotorpin1 = 12; // 直流电机信号输出
const int leftmotorpin2 = 3;
const int rightmotorpin1 = 13;
const int rightmotorpin2 = 11;
const int HeadServopin = 2; // 舵机信号输出 只有9或10接口可利用
const int Sharppin = 3; // 红外输入
const int maxStart = 800; //run dec time
// Variables
int isStart = maxStart; //启动
int currDist = 0; // 距离
boolean running = false;
void setup() {
Serial.begin(9600); // 开始串行监测
//信号输入接口
pinMode(EchoPin, INPUT);
pinMode(TrigPin, OUTPUT);
pinMode(Sharppin, INPUT);
pinMode(HeadServopin, OUTPUT);
pinMode(leftmotorpin1, OUTPUT);
pinMode(leftmotorpin2, OUTPUT);
pinMode(rightmotorpin1, OUTPUT);
pinMode(rightmotorpin1, OUTPUT);
//信号输出接口
//for (int pinindex = 3; pinindex < 11; pinindex++) {
// pinMode(pinindex, OUTPUT); // set pins 3 to 10 as outputs
//}
//舵机接口
headservo.attach(HeadServopin);
//启动缓冲活动头部
headservo.write(70);
delay(2000);
headservo.write(20);
delay(2000);
}
void loop() {
if(DEBUG){
Serial.print("running:");
if(running){
Serial.println("true");
}
else{
Serial.println("false");
}
}
if (isStart <= 0) {
if(running){
totalhalt(); // stop!
}
int findsomebody = digitalRead(Sharppin);
if(DEBUG){
Serial.print("findsomebody:");
Serial.println(findsomebody);
}
if(findsomebody > 0) {
isStart = maxStart;
}
delay(4000);
return;
}
isStart--;
delay(100);
if(DEBUG){
Serial.print("isStart: ");
Serial.println(isStart);
}
currDist = MeasuringDistance(); //读取前端距离
if(DEBUG){
Serial.print("Current Distance: ");
Serial.println(currDist);
}
if(currDist > 30) {
nodanger();
}
else if(currDist < 15){
backup();
randTrun();
}
else {
//whichway();
randTrun();
}
}
//测量距离 单位厘米
long MeasuringDistance() {
long duration;
//pinMode(TrigPin, OUTPUT);
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(5);
digitalWrite(TrigPin, LOW);
//pinMode(EchoPin, INPUT);
duration = pulseIn(EchoPin, HIGH);
return duration / 29 / 2;
}
// 前进
void nodanger() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
return;
}
//后退
void backup() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
delay(1000);
}
//选择路线
void whichway() {
running = true;
totalhalt(); // first stop!
headservo.write(20);
delay(1000);
int lDist = MeasuringDistance(); // check left distance
totalhalt(); // 恢复探测头
headservo.write(120); // turn the servo right
delay(1000);
int rDist = MeasuringDistance(); // check right distance
totalhalt(); // 恢复探测头
if(lDist < rDist) {
body_lturn();
}
else{
body_rturn();
}
return;
}
//重新机械调整到初始状态
void totalhalt() {
digitalWrite(leftmotorpin1, HIGH);
analogWrite(leftmotorpin2, 20);
digitalWrite(rightmotorpin1, HIGH);
analogWrite(rightmotorpin2, 20);
headservo.write(70); // set servo to face forward
running = false;
return;
delay(1000);
}
//左转
void body_lturn() {
running = true;
digitalWrite(leftmotorpin1, LOW);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, HIGH);
analogWrite(rightmotorpin2, 100);
delay(1500);
totalhalt();
}
//右转
void body_rturn() {
running = true;
digitalWrite(leftmotorpin1, HIGH);
analogWrite(leftmotorpin2, 100);
digitalWrite(rightmotorpin1, LOW);
analogWrite(rightmotorpin2, 100);
delay(1500);
totalhalt();
}
void randTrun(){
long randNumber;
randomSeed(analogRead(0));
randNumber = random(0, 10);
if(randNumber > 5) {
body_rturn();
}
else
{
body_lturn();
}
}
回复: 2013年春季《电子设计竞赛》课程之arduino智能小车实训
老师 你好 如果把程序中两个电机的电平都改LOW 小车就不会动 只能一个前转一个后转 也就是只能一个LOW 一个HIGH
李曦- 帖子数 : 1
注册日期 : 13-05-12
更正 pinMode(N2,OUTPUT);
void setup()
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
{
// put your setup code here, to run once:
pinMode(N1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(N2,OUTPUT);
pinMode(PWM2,OUTPUT);
}
arduino给arduino烧录bootloader
http://www.haogongju.net/art/1959020
使用arduino有时候会比较郁闷的是bootloader错误导致无法烧录新的程序到arduino。这个时候需要重新烧录bootloader。
可以参考官网的教程:http://arduino.cc/en/Tutorial/ArduinoISP ,这里就自己的操作过程作个总结,也许可以让你更清楚一些具体流程。
1 将一块正常板子准备好,具体包括:通过usb线连接电脑,选择File>examples>ArduinoISP,将这个代码烧录进去。 2 连接好问题板子,具体的连线看图。如果你的正常板子是UNO,需要使用一个10uf的电容连接正常板子的reset和GND。 3 烧录bootloader:a> 在Tools>board菜单上,选择问题板子型号。b> 在Tools>Programmer里选择 Arduino as ISP 。 c> 选择Tools>Burn Bootloader即开始烧录。 如果出现错误请根据错误进行处理,一般是连线错误,重连后再次点击烧录即可。 如果正常会在20s内提示烧录成功。
使用arduino有时候会比较郁闷的是bootloader错误导致无法烧录新的程序到arduino。这个时候需要重新烧录bootloader。
可以参考官网的教程:http://arduino.cc/en/Tutorial/ArduinoISP ,这里就自己的操作过程作个总结,也许可以让你更清楚一些具体流程。
1 将一块正常板子准备好,具体包括:通过usb线连接电脑,选择File>examples>ArduinoISP,将这个代码烧录进去。 2 连接好问题板子,具体的连线看图。如果你的正常板子是UNO,需要使用一个10uf的电容连接正常板子的reset和GND。 3 烧录bootloader:a> 在Tools>board菜单上,选择问题板子型号。b> 在Tools>Programmer里选择 Arduino as ISP 。 c> 选择Tools>Burn Bootloader即开始烧录。 如果出现错误请根据错误进行处理,一般是连线错误,重连后再次点击烧录即可。 如果正常会在20s内提示烧录成功。
用好板子救程序出错的板子
下午回来后帮几个同学修了下板子。没用电容也成功了,Burn Bootloader后两边都小灯都闪持续了20秒!!但有的板子还是不行!!
livingball- 帖子数 : 1
注册日期 : 13-06-06
回复: 2013年春季《电子设计竞赛》课程之arduino智能小车实训
多试几次,实在不行的话返回给我,我去找厂家使用专门的下载器重新下载bootloader
附录:
http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader
What's a bootloader?
See this page for an explanation of what a bootloader is and why we're using one.
Not using a bootloader
If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you can burn your sketches using an external programmer.
Burning the Bootloader
To burn the bootloader, you'll need to buy an ***R-ISP (in-system programmer), USBtinyISP or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.
Make sure you have the right item selected in the Tools | Board menu. Then, just launch the appropriate command from the Tools > Burn Bootloader menu of the Arduino environment. Burning the bootloader may take 15 seconds or more, so be patient.
Bootloading an Arduino Mini
Here are some instructions on bootloading the Mini, thanks to Gian Pablo Vilamil.
It still doesn't work! (parallel programmer on Windows XP)
Windows XP may be polling your parallel port and disrupting the bootloader burning process. You'll need this registry patch:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Parport\Parameters]
"DisableWarmPoll"=dword:00000001
See this forum thread for details.
Versions of the bootloader
There are different versions of the bootloader - both in order to work on different hardware and because it has changed over time.
The current bootloaders (i.e. the ones included in Arduino 0009) are almost identical for the Diecimila and NG (with ATmega168). They both run at 19200 baud and take up 2 KB of flash memory on the ATmega168. The only differences is the time the bootloader waits for a new program to arrive and the number of times it flashes the pin 13 LED when it starts. Because of the automatic reset on the Diecimila, its bootloader needs only wait a very short amount of time (less than a second) - to save time, it also flashes the pin 13 LED only once. The NG bootloader waits about 6-8 seconds and flashes the LED three times.
The bootloader that actually shipped on the Arduino NG is slightly different. It enables the internal pullup resistor on pin 6, and doesn't enable the internal pullup on the RX pin. Nor does it timeout upon receiving invalid data, so if you send data to it immediately after it resets, your sketch will never start.
The Arduino BT bootloader does some initial configuration of the bluetooth module.
The ATmega8 bootloader only takes up 1 KB of flash. It does not timeout when it receives invalid data, you need to make sure that no data is sent to the board during the 6-8 seconds when the bootloader is running.
Some ancient versions of the bootloader run at 9600 baud (instead of 19200). In order to successfully upload sketches to boards with this bootloader, you'll need to change the serial.download_rate in your preferences file to 9600.
Third parties have also worked on the bootloader. This page is link to some other bootloader development
How does it work?
The "Burn Bootloader" commands in the Arduino environment use an open-source tool, avrdude. There are four steps: unlocking the bootloader section of the chip, setting the the fuses on the chip, uploading the bootloader code to the chip, and locking the bootloader section of the chip. These are controlled by a number of preferences in the Arduino preferences file.
For the ATmega8 bootloader, these are:
bootloader.atmega8.programmer (default value: stk500) is the protocal used by the bootloader.
bootloader.atmega8.unlock_bits (default value: 0xFF) is the value to write to the ATmega8 lock byte to unlock the bootloader section.
bootloader.atmega8.high_fuses (default value: 0xca) is the value to write to the high byte of the ATmega8 fuses.
bootloader.atmega8.low_fuses (default value: 0xdf) is the value to write to the low byte of the ATmega8 fuses.
bootloader.atmega8.path (default value: bootloader) is the path (relative to the Arduino application directory) containing the precompiled bootloader.
bootloader.atmega8.file (default value: ATmegaBOOT.hex) is the name of the file containing the precompiled bootloader code (in bootloader.path).
bootloader.atmega8.lock_bits (default value: 0x0F) is the value to write to the ATmega8 lock byte to lock the bootloader section (so it doesn't get accidently overwritten when you upload a sketch).
For the ATmega168, these are (where <BOARD> is either "diecimila" or "ng"):
bootloader.atmega168-<BOARD>.programmer (default value: avrispmkii) is the protocal used by the bootloader.
bootloader.atmega168-<BOARD>.unlock_bits (default value: 0x3F) is the value to write to the ATmega168 lock byte to unlock the bootloader section.
bootloader.atmega168-<BOARD>.extended_fuses (default value: 0x00) is the value to write to the high byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.high_fuses (default value: 0xdd) is the value to write to the high byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.low_fuses (default value: 0xff) is the value to write to the low byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.path (default value: bootloader168) is the path (relative to the Arduino application directory) containing the precompiled bootloader.
bootloader.atmega168-<BOARD>.file (default value: ATmegaBOOT_168_<BOARD>.hex) is the name of the file containing the precompiled bootloader code (in bootloader.path).
bootloader.atmega168-<BOARD>.lock_bits (default value: 0x0F) is the value to write to the ATmega168 lock byte to lock the bootloader section (so it doesn't get accidently overwritten when you upload a sketch).
Source Code
The bootloader source code is available.
附录:
http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader
What's a bootloader?
See this page for an explanation of what a bootloader is and why we're using one.
Not using a bootloader
If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you can burn your sketches using an external programmer.
Burning the Bootloader
To burn the bootloader, you'll need to buy an ***R-ISP (in-system programmer), USBtinyISP or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.
Make sure you have the right item selected in the Tools | Board menu. Then, just launch the appropriate command from the Tools > Burn Bootloader menu of the Arduino environment. Burning the bootloader may take 15 seconds or more, so be patient.
Bootloading an Arduino Mini
Here are some instructions on bootloading the Mini, thanks to Gian Pablo Vilamil.
It still doesn't work! (parallel programmer on Windows XP)
Windows XP may be polling your parallel port and disrupting the bootloader burning process. You'll need this registry patch:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Parport\Parameters]
"DisableWarmPoll"=dword:00000001
See this forum thread for details.
Versions of the bootloader
There are different versions of the bootloader - both in order to work on different hardware and because it has changed over time.
The current bootloaders (i.e. the ones included in Arduino 0009) are almost identical for the Diecimila and NG (with ATmega168). They both run at 19200 baud and take up 2 KB of flash memory on the ATmega168. The only differences is the time the bootloader waits for a new program to arrive and the number of times it flashes the pin 13 LED when it starts. Because of the automatic reset on the Diecimila, its bootloader needs only wait a very short amount of time (less than a second) - to save time, it also flashes the pin 13 LED only once. The NG bootloader waits about 6-8 seconds and flashes the LED three times.
The bootloader that actually shipped on the Arduino NG is slightly different. It enables the internal pullup resistor on pin 6, and doesn't enable the internal pullup on the RX pin. Nor does it timeout upon receiving invalid data, so if you send data to it immediately after it resets, your sketch will never start.
The Arduino BT bootloader does some initial configuration of the bluetooth module.
The ATmega8 bootloader only takes up 1 KB of flash. It does not timeout when it receives invalid data, you need to make sure that no data is sent to the board during the 6-8 seconds when the bootloader is running.
Some ancient versions of the bootloader run at 9600 baud (instead of 19200). In order to successfully upload sketches to boards with this bootloader, you'll need to change the serial.download_rate in your preferences file to 9600.
Third parties have also worked on the bootloader. This page is link to some other bootloader development
How does it work?
The "Burn Bootloader" commands in the Arduino environment use an open-source tool, avrdude. There are four steps: unlocking the bootloader section of the chip, setting the the fuses on the chip, uploading the bootloader code to the chip, and locking the bootloader section of the chip. These are controlled by a number of preferences in the Arduino preferences file.
For the ATmega8 bootloader, these are:
bootloader.atmega8.programmer (default value: stk500) is the protocal used by the bootloader.
bootloader.atmega8.unlock_bits (default value: 0xFF) is the value to write to the ATmega8 lock byte to unlock the bootloader section.
bootloader.atmega8.high_fuses (default value: 0xca) is the value to write to the high byte of the ATmega8 fuses.
bootloader.atmega8.low_fuses (default value: 0xdf) is the value to write to the low byte of the ATmega8 fuses.
bootloader.atmega8.path (default value: bootloader) is the path (relative to the Arduino application directory) containing the precompiled bootloader.
bootloader.atmega8.file (default value: ATmegaBOOT.hex) is the name of the file containing the precompiled bootloader code (in bootloader.path).
bootloader.atmega8.lock_bits (default value: 0x0F) is the value to write to the ATmega8 lock byte to lock the bootloader section (so it doesn't get accidently overwritten when you upload a sketch).
For the ATmega168, these are (where <BOARD> is either "diecimila" or "ng"):
bootloader.atmega168-<BOARD>.programmer (default value: avrispmkii) is the protocal used by the bootloader.
bootloader.atmega168-<BOARD>.unlock_bits (default value: 0x3F) is the value to write to the ATmega168 lock byte to unlock the bootloader section.
bootloader.atmega168-<BOARD>.extended_fuses (default value: 0x00) is the value to write to the high byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.high_fuses (default value: 0xdd) is the value to write to the high byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.low_fuses (default value: 0xff) is the value to write to the low byte of the ATmega168 fuses.
bootloader.atmega168-<BOARD>.path (default value: bootloader168) is the path (relative to the Arduino application directory) containing the precompiled bootloader.
bootloader.atmega168-<BOARD>.file (default value: ATmegaBOOT_168_<BOARD>.hex) is the name of the file containing the precompiled bootloader code (in bootloader.path).
bootloader.atmega168-<BOARD>.lock_bits (default value: 0x0F) is the value to write to the ATmega168 lock byte to lock the bootloader section (so it doesn't get accidently overwritten when you upload a sketch).
Source Code
The bootloader source code is available.
您在这个论坛的权限:
您不能在这个论坛回复主题