标签: arduino-ide

自定义库的 Arduino Due 条件编译常量

我正在编写一个自定义库,它在 Arduino Uno 上正常工作。但是,我现在已经掌握了 Arduino Due,我需要定义一些板特定的引脚常量。

我知道对于大多数电路板,您可以#ifdef使用\\arduino-1.5.2\hardware\tools\avr\avr\include\avr\io.h. 例如:

#if defined (__AVR_ATmega128__)
    //do something specific
#endif
Run Code Online (Sandbox Code Playgroud)

有人知道哪个是用于到期的正确常量吗?

arduino arduino-ide

3
推荐指数
1
解决办法
3821
查看次数

arduino 突然显示“avrdude: ser_open(): can't open device "\\.\COM3" after last upload

我正在使用 arduino uno 制作声音检测器。我上传了一个程序,在代码中发现错误,它返回了不合理的大数字。我还认为我为模块使用了错误的代码,但它以可以与正确代码正常工作的方式连接。

我上传的代码是:

const int ledPin =13;
const int middleValue = 512;
const int numberOfSamples =128;

int sample;
long signal;
long averageReading;

long runningAverage = 0;
const int averagedOver = 16;

const int threshold=400;

void setup(){
    pinMode(ledPin, OUTPUT)
    Serial.begin(9600)
}

void loop(){
    long sumOfSquares = 0;
    for (int i=0; i<numberOfSamples; i++){
        sample = analogRead(0);
        signal = (sample - middleValue);
        signal *= signal;
        sumOfSquares += signal;
    }
    averageReading = sumOfSquares/numberOfSamples;
    runningAverage=(((averagedOver -1 )*runningAverage)+averageReading)/averagedOver;

    if(runningAverage>threshold){
        digitalWrite(ledPin, HIGH);
    }else{
        digitalWrite(ledPin, LOW); …
Run Code Online (Sandbox Code Playgroud)

arduino arduino-ide arduino-uno

3
推荐指数
1
解决办法
4万
查看次数

无参数构造函数

我是一个非常有经验的.net开发人员,但是对Arduino和C / C ++还是陌生的,我正在尝试创建我的第一个库,该库是7段LED显示屏的简单驱动程序。我有很多钝的编译器错误,但本着一件事的精神,这是第一次。我想在类中添加一个无参数的构造函数,当我进行库编译时很好,但是当我尝试在草图中使用该类时,编译器为我提供了一个相当晦涩的“请求'sevenSegmentLed'中的成员'setDigit',非类类型'SevenSegmentLed()“

最简单的示例代码如下:

#ifndef SevenSegmentLed_h
#define SevenSegmentLed_h
#include "Arduino.h"

class SevenSegmentLed
{
  public:
    void setDigit(int digit);
    SevenSegmentLed();
};

#endif

#include "Arduino.h"
#include "SevenSegmentLed.h"

SevenSegmentLed::SevenSegmentLed()
{

}

void SevenSegmentLed::setDigit(int digit)
{       

}

#include "SevenSegmentLed.h"
SevenSegmentLed sevenSegmentLed();

void setup() {
  sevenSegmentLed.setDigit(4);
}

void loop() {
  // put your main code here, to run repeatedly:

}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将构造函数签名更改为:SevenSegmentLed(int wtf);并实例化它:SevenSegmentLed sevenSegmentLed(1);编译就很好。如参数所示,WTF?

c++ arduino most-vexing-parse arduino-ide

3
推荐指数
1
解决办法
760
查看次数

如何确保数据类型与C++中的数据类型一样大

是否有一种简单的方法可以确保数据类型在C/C++中的不同平台和体系结构中保持相同的大小?

在C++中,假设我编写了一个假设的,简单的程序:

#include <iostream>

int foo;

int main(void)
{
    std::cout<<"Size of foo is "<<sizeof(foo)<<" bytes."<<std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所有这个程序都打印任意整数数据类型的大小并退出.在我的机器上,它返回foo4个字节的大小(我有一个64位机器).

但是,假设我为Arduino或其他ATMega驱动板编写此程序:

int foo;
void setup()
{
    Serial.begin(9600);
    Serial.print("Size of foo is ");
    Serial.print(sizeof(foo));
    Serial.println(" bytes.");
}
void loop(){}
Run Code Online (Sandbox Code Playgroud)

在我的Arduino UNO板上,这只返回2(与short我的机器相同的大小).

是否可以创建(优选跨平台)标头或声明以确保数据类型的大小是一定的大小,以免遇到精度问题或数量非常大的问题?

理想情况下,这不仅可以用于Arduino板,还可以用于其他紧凑型MCU(如PicKit).

我对Arduino和整个Arduino IDE都比较陌生,所以请原谅我,如果我错过了一些非常简单的东西.

c++ types arduino arduino-ide arduino-uno

3
推荐指数
1
解决办法
91
查看次数

如何解决这个问题:从'const char *'到'const uint8_t *的无效转换

我安装了此SHA库:https : //github.com/Cathedrow/Cryptosuite。我想使用Win上安装的Arduino IDE 1.6.7实现HMAC256。10,控制器为ATMEGA328。

我复制了他们网页中给出的示例。我还是新手,想测试一下。我在Arduino IDE中编写了此代码。

#include "sha256.h"

void setup() {
    // put your setup code here, to run once:
    uint8_t *hash;
    //static const char hash[450]={};
    //const char *hash; hash={};
    Sha256.initHmac("hash key",8); // key, and length of key in bytes
    Sha256.print("This is a message to hash");
    hash = Sha256.resultHmac();
    //Serial.print(hash,HEX);
}

void loop() {
    // put your main code here, to run repeatedly:
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

从'const char *'到'const uint8_t * {aka const unsigned char *}'的无效转换'[-fpermissive]

我不知道为什么会这样。该示例是从库站点获取的原始数据。你能帮我吗?

编辑: …

c++ arduino sha hmac arduino-ide

3
推荐指数
1
解决办法
2万
查看次数

Arduino DUE(SAM板)的boards.txt的位置

我使用1.6.7 Arduino IDE,并为DUE板安装了“ Arduino SAM板(32位ARM Cortex-M3)”项目,它工作正常。

但是,我想调整boards.txt文件中的一些构建参数。问题:我没有INSTALL/hardware/arduino/sam文件夹!我确实有传统INSTALL/hardware/arduino/avr文件夹,但是在此文件夹boards.txt中不包含DUE的设置。

  • 在哪里可以找到DUE的设置?
  • 我应该boards.txt在新sam/文件夹中创建自己的新文件吗?它的默认内容应该是什么?

arduino arduino-ide arduino-due

3
推荐指数
1
解决办法
5642
查看次数

while...else Arduino 语句

是否有可能在 Arduino 中的 while 循环之后添加 else,就像 Java 或 C# 中那样?像这样的东西:

while(condition){
  doThingA;
} else{
  doThingB;
}
Run Code Online (Sandbox Code Playgroud)

arduino arduino-ide

3
推荐指数
1
解决办法
1万
查看次数

使用 ESP8266 在 Arduino 中获取网关地址

我需要 ESP8266 的默认网关 IP 地址。我知道在 LUA 中,您可以使用以下代码检索它:

ip, netmask, gateway = wifi.sta.getip()
print(gateway)
Run Code Online (Sandbox Code Playgroud)

但是如何使用 Arduino/C++?

arduino arduino-ide esp8266

3
推荐指数
1
解决办法
4185
查看次数

这个函数调用“ delay +(1000)”在语法上是否正确?

我正在编写一个小代码,以在传感器读数超过特定阈值时启用蜂鸣器。要启用一秒钟蜂鸣器,我给了1000毫秒的延迟通过调用这个函数:delay(1000)。但是,我是随机输入的delay+(1000),并且编译良好。该函数调用在语法上正确吗?

我已经在Arduino IDE上尝试过此代码。它可以编译,但对于avr-gcc或avr-g ++或gcc / g ++来说并非如此。

我希望delay +(1000)无法编译,因为它似乎不是有效的c / c ++语法。

更新1:

使用Arduino IDE编译并上传以下代码片段至Arduino UNO:

void setup() 
{
    Serial.begin(9600);
}

void loop()
{
    int x = delay+(1000);
    Serial.println(x);
}
Run Code Online (Sandbox Code Playgroud)

它连续打印一个随机数1132,没有任何延迟。(因此1132 =>功能指针地址+ 100?)

我还观察到delay+(1000)delay-(1000)编译,但对于delay*(1000)和则并非如此delay/(1000)。编译器给出以下错误:

sketch_jun09a:8:错误:类型为“ void(long unsigned int)”和>“ int”类型的无效操作数为二进制“ operator *”

     delay*(1000);
               ^
Run Code Online (Sandbox Code Playgroud)

但是,int t = (int)delay*(1000);编译效果很好。

更新2:

根据以下答案,delay<operator>(x)仅执行函数指针算术(使用一元或二进制运算符),而不执行函数本身。

我使用了以下代码片段:

void setup()
{
    Serial.begin(9600);
}
int custom()
{
    Serial.println("hello");
    return 0;
}
void loop() …
Run Code Online (Sandbox Code Playgroud)

c c++ arduino-ide

3
推荐指数
1
解决办法
122
查看次数

PermissionError(13, '连接到系统的设备无法运行。', None, 31)串行端口 COM4

我对使用 ESP8266 很陌生,我尝试上传这个简单的脚本

void setup() {
  pinMode(D4, OUTPUT);

}

void loop() {
  digitalWrite(D4, HIGH);
  delay(1000);
  digitalWrite(D4, LOW);
  delay(1000);

} 
Run Code Online (Sandbox Code Playgroud)

到节点 mcu(ESP8266) 但我不断收到此错误esptool.py v3.0 A fatal esptool.py error occurred: Cannot configure port, something went wrong. Original message: PermissionError(13, 'A device attached to the system is not functioning.', None, 31)Serial port COM4

任何人回答这个问题,一步一步解释它,并记住我对 esp8266 的知识为零。我已经尝试安装驱动程序,但仍然出现相同的错误。

arduino-ide nodemcu esp8266

3
推荐指数
1
解决办法
1万
查看次数