html tool

显示标签为“Arduino”的博文。显示所有博文
显示标签为“Arduino”的博文。显示所有博文

2015年3月5日星期四

emulare 仿真 arduino的奇怪问题--PB5是Pin13吗


使用emulare 仿真,参考:http://emulare.sourceforge.net/,
好奇怪的现象,代码中写的是
// 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
但运行后的效果是PB5(PCINT5)为输出,不是13?!

我选的cpu是默认的ATMega,好吧,还是我对芯片不是很了解,不过至少可以用了,并且可以通过run后的灰质效果判断哪个是output。

2015年3月4日星期三

arduino中输入查找编译后的hex文件

add:http://www.geek-workshop.com/thread-4227-1-1.html



preferences->show verbose output dearing 的 conpilation 选上就ok了:)

2015年2月5日星期四

arduino 的赋值语句和串口监视器问题

 问题:arduino的赋值语句不支持两个*连用
原始code如下:
unsigned long oldtime=8*3600*1000;
unsigned long testtime=3*60*1000;
...
void loop(){
...
   if (time> testtime){
    Serial.println("3 min");
  }
...

结果测试时可远远到不了3分钟就输出了,加调试后发现testtime为4294950688,好吧太郁闷了。
按说unsigned long的溢出范围还大的很呢?why?
后来修改为如下就好了:
unsigned long oldtime=8*3600000;
unsigned long testtime=3*60000;
...
void loop(){
...
   if (time> testtime){
    Serial.println("3 min");
  }
...
看来只是类c语言吧,是不支持多个运算符号啊!好吧:)[go]了一下也没发现官方帮助说不可以,算bug吗?嘻嘻,不理它了知道就这么用吧!
2.arduino编译环境中的串口监视器每次打开都对串口断电的问题
loop代码如下:
void loop(){
  time = millis();
  //prints time since program started
  Serial.println(time);
  x=x+1;
  Serial.print("X: ");
  Serial.print(x);
  // wait a second so as not to send massive amounts of data
  delay(1000);
   if (time> testtime){
    Serial.println("3 min");
    //_Closepower();
    //delay(3000);
  }
  if (time> oldtime){
    Serial.println("8 hours is start");
    _Openpower();
    delay(3000);
  }
}

本 来是个很简单的dome,想测试一下mil有lis()的50天才复位的可靠性,但发现3分钟测试都问题,每次使用Arduino的工具中的串口调试工 具,发现都是从2开始记X,明明没有开关过,理论上应该是开机运行time,不是每个串口打开开始算啊?!why?加了pin=18的一个led测试,调 试代码如下:
void setup(){
  x=1;
  Serial.begin(9600);
    //initialise the power pin as an output
   pinMode(_powerPin,OUTPUT); 
   digitalWrite(_powerPin,LOW);
   _Closepower();
}
发现每次关闭串口调试器后led还是正常开的,但每次重新打开串口调试器后,led就灭了再开。好吧!开始怀疑电源了,为什么串口输出是相同逻辑,而我只相信led呢?:) 开始转usb电源测试,不再看串口了,只看led。好吧 换了电源后就再也没有那个问题了。
看来就是arduino编译环境中的串口监视每次打开时都重新对串口断电加点了,我的板子串口测试时,直接用串口供电的,当然就有这个了。

后记:
好久,没有软硬联调了,吞说的有道理就是我只做数电,逻辑和物理还是有不少区分的,多动手才是正理。:)

2015年2月3日星期二

arduino - millis

add:http://arduino.cc/en/Reference/Millis
[popexizhi:作为DH2321芯片的替代,delay()之后发现millis,也可以try。看来还是多看eg有好处啊:)]

----------------------------------------------

Description

Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.
[popexizhi:50days,这个是工业级别的证明吗?还最大max的溢出值范围:)好吧log计算都忘记了,也没算出来:)]

Parameters

None

Returns

Number of milliseconds since the program started (unsigned long)
[popexizhi: unsigned long 的逻辑范围是类型取值范围: 0~4294967295 即 0~(2的32次方-1),50days是180000000毫秒左右.上面的应该是工业级别的硬件范围,4294967295换算完是3.268年左右]

Example

unsigned long time;

void setup(){
  Serial.begin(9600);
}
void loop(){
  Serial.print("Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
  // wait a second so as not to send massive amounts of data
  delay(1000);
}
[popexizhi:next 在串口中调试一下]

Tip:

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints.
-------------------------------------------------------
PS:
[popexizhi:测试8小时的Dome,调试一下硬件看看效果如何,]
unsigned long time;
unsigned long oldtime=8*3600*1000;

void setup(){
  Serial.begin(9600);
}
void loop(){
  Serial.print("Time: ");
  time = millis();
  //prints time since program started
  Serial.println(time);
  // wait a second so as not to send massive amounts of data
  delay(1000);
  if (time> oldtime){
    Serial.println("8 hours is start");
    //继电器操作位置
  }
}

2015年1月28日星期三

avrdude: stk500_getsync(): not in sync: resp=0x00错误提示问题原因汇总

add:http://www.geek-workshop.com/thread-627-1-1.html
---------------------------传说中的分割线--------------------------------
问题:avrdude: stk500_getsync(): not in sync: resp=0x00错误
就是测试delay在计时时无中断影响时,没有喂狗操作,多长时间还可以使用的小Dome,结果下载时一直如上。

结果:
下载的时候,arduino控制板上接了其他扩展板(使用D0,D1口的基本都会出问题,这两个口是用来通信下载程序的。)如果接了其他扩展板不能用,可以先拔掉扩展板再次尝试重新下载程序
PS:
测试如下

void testdelay(){
  int time=1000*60; //1min=60s * 1000 miliseconds
  Serial.print("time stat");
  delay(2000);
  Serial.print("time 2s");     //到这里还是可以的
  delay(time*5);                //这里就挂掉了,好吧,我查官方帮助这里可以是unsigned long[http://www.arduino.cc/en/Reference/Delay]  函数上限应该是

4394967295,但是好吧,我上位机写多了,方法上限不是物理上限,改把加循环喂狗吧,这样看之前想用中断直接计时方式应该会有相同问题,看来下一步还是要用DS3231帮忙才行啊。

  Serial.print("time * 5 is over");
  delay(time*10);
  Serial.print("time * 10 is over");
}
好吧,地址中还提供了其他的解释,转如下:
-------------------------------------------------------原文--------------------------------
这个错误代表着就是无法通过USB口与arduino控制板进行通信,下面总结一下这个问题常见的几个原因。

1,arduino控制板或者COM口没有选对,这种问题最简单,照下图的选项选择对了就OK。

avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude: stk500_getsync(): not in sync: resp=0x00 
2012-3-11 21:57 上传
下载附件 (56.11 KB) 
avrdude: stk500_getsync(): not in sync: resp=0x00


2,下载的时候,arduino控制板上接了其他扩展板(使用D0,D1口的基本都会出问题,这两个口是用来通信下载程序的。)如果接了其他扩展板不能用,可以先拔掉扩展板再次尝试重新下载程序。

3,bootloader损坏,这种情况下需要重新刷bootloader。

4,驱动未安装好。(目前遇到ghost版本,或者精简版win7系统安装uno驱动时,无法安装的问题。这种情况,需要重装系统。ghost版或者精简版操作系统,请谨慎安装,后患无穷。)

5,芯片不停的复位,无法与外界通讯。案例,我测试了一个看门狗,复位时间很短,原本想测试用的,结果就出现上述故障了。
解决办法:在IDE快要upload的时候,插入USB,反复多次,抢个时间差,就可以写入了

2015年1月14日星期三

arduino的延时处理

def:自动计数问题,一直想使用sleep,go之后发现arduino的sleep是cpu挂起和终端的相关内容,以为没有此类方法
add:http://arduino.cc/en/Reference/Delay
解释:看arduino的Reference时发现delay不就是自己要的sleep吗?只是毫秒单位,自己的目标是x小时,只是担心delay过长芯片是否有其他意外,但这个可以测试啊,嘻嘻,如果这样就不用调试时钟芯片了,测试一下吧!:)
说明:
Certain things do go on while the delay() function is controlling the Atmega chip however, because the delay function does not disable interrupts. Serial communication that appears at the RX pin is recorded, PWM (analogWrite) values and pin states are maintained, and interrupts will work as they should.
[popexizhi]这样看来delay中没有考虑中断问题,自己的如果使用这个计时在使用终端并用时会有问题,好吧还是先测试一下效果吧.

arduino的string比较

def:定义power 开关参数时使用的string,但char比较时发现arduino中字符串比较函数无法使用
参考:http://arduino.cc/en/Tutorial/StringComparisonOperators
解释:
arduino支持string对象,提供比较运算符的重载功能
//equal
  // two strings equal:
  if (stringOne == "this") {
    Serial.println("StringOne == \"this\"");
  }
//也可以用equals描述
if (stringOne.equals(stringTwo)) {

特殊说明:
The greater than and less than operators evaluate strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" and "1" < "2", but "999"> "1000" because 9 comes after 1.
[popexizhi]
><的重载是使用string的字符串比较,所以999与1000的结果就无可厚非了:).本来想解释但发现只要用string的观点看就没有什么可以解释的了:)
Caution: String comparison operators can be confusing when you're comparing numeric strings, because you're used to thinking of them as numbers, not strings. If you have to compare numbers, compare them as ints, floats, or longs, and not as Strings.
[popexizhi]
这个说明arduino还是很java或c++的类型比较用指定类型不要期望string做什么别的:)

2014年7月17日星期四

xizhi plan-arduino uno的spi and string

robot using

  • uml:总体结构图:

  • 昨天调试的是图中green部分,ardunio上的code
  • 问题
    • arudino
      • string 匹配 不是 == ?
        自己定义如下:
        String getcon = String(thisChar);
        if (getcon== "open" ){
              //open power
              _Openpower();
              }
        thisChar远程输出为open后如何都不执行if中的定义。郁闷,最后将命令改为单字节char的匹配是转为int比较的,如下:
        if(int(thisChar)==int("o") )
        {
              //open power
              _Openpower();
              }
        调试通过了,但这个是个问题,要搞清楚一下
         
    •  
    •  
  • [note]
    • SPI使用时会占用13口,自己测试时开始定义pin13为OUTPUT,调试时led总是hight,后来吞提醒才发现的,要好好看手册啊!
      add:http://arduino.cc/en/Tutorial/BarometricPressureSensor
      占用的是13,12,11