标签: arduino

如何使用 MSP 从 CleanFlight 读取陀螺仪信息?

使用 Arduino,我将如何使用 MultiWii 串行协议从飞行控制器中的陀螺仪获取姿态?

arduino

0
推荐指数
1
解决办法
3768
查看次数

ESP8266 从网页获取请求返回连接器被拒绝

我希望能够将数据从网页发送到 esp8266 并控制引脚,每当我按下网页上的按钮时,它都会返回 ESP 的 i 地址和CONNECTION REFUSED. 我究竟做错了什么?

ESP代码:

void setup() {
  Serial.begin(115200);
  delay(100);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to: ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while( WiFi.status() != WL_CONNECTED){
      delay(500);
      Serial.print(".");
     }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Netmask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(WiFi.gatewayIP());

}

int value = 0;


void loop() {
   HTTPClient http;

   http.begin("192.168.0.24:80");
   int httpCode = http.GET();

   if(httpCode > 0){
    String payload = http.getString();
    Serial.println(payload);
    }
    http.end();
    delay(3000);

}
Run Code Online (Sandbox Code Playgroud)

HTML网站:

<html>
<head>
  <title>ESP8266 toggle page</title>
</head>
  <body> …
Run Code Online (Sandbox Code Playgroud)

get arduino esp8266

0
推荐指数
1
解决办法
1135
查看次数

Arduino 十六进制到十进制转换

我需要将十六进制字符串转换为十进制值。我使用了以下方法。但有时它返回错误的十进制值。

十六进制字符串的格式为“00 00 0C 6E”

unsigned long hexToDec(String hexString) {
  unsigned long decValue = 0;
  int nextInt;
  for (long i = 0; i < hexString.length(); i++) {
    nextInt = long(hexString.charAt(i));
    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
    if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
    if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
    nextInt = constrain(nextInt, 0, 15); …
Run Code Online (Sandbox Code Playgroud)

c++ hex arduino decimal

0
推荐指数
1
解决办法
3037
查看次数

pyFirmata 的 write() 函数

我正在研究由 Pratik Desai(令人讨厌的聪明人)编写的“Python Programming for Arduino”一书。

我陷入了练习,学生正在学习实现一个滑块,该滑块可以改变连接到引脚的 LED 的强度。我标记了代码不能正常工作的地方。

代码是:

import tkinter
from pyfirmata import ArduinoMega
from time import sleep

port = '/dev/ttyACM0'
board = ArduinoMega(port)
sleep(5)
lenPin = board.get_pin('d:11:o')

top = tkinter.Tk()
top.title('Specify time using Entry')
top.minsize(300, 30)
timePeriodEntry = tkinter.Entry(top, bd=5, width=25)
brightnessScale = tkinter.Scale(top, from_=0, to=100, 
orient=tkinter.HORIZONTAL)
brightnessScale.grid(column=2, row=2)
tkinter.Label(top, text='Time (seconds)').grid(column=1, row=1)
tkinter.Label(top, text='Brightness (%)').grid(column=1, row=2)

def onStartPress():
    time_period = timePeriodEntry.get()
    time_period = float(time_period)
    ledBrightness = brightnessScale.get()
    ledBrightness = float(ledBrightness)
    startButton.config(state=tkinter.DISABLED)
    lenPin.write(ledBrightness / 100.0) # this …
Run Code Online (Sandbox Code Playgroud)

python arduino firmata python-3.x

0
推荐指数
1
解决办法
1992
查看次数

将字符串转换为MAC地址

在SPIFFS中的文件内,我将以"XX:XX:XX:XX:XX:XX"的形式保存有关mac地址的信息.当我读取文件时,我需要将它从STRING切换为十六进制值数组.

uint8_t* str2mac(char* mac){
  uint8_t bytes[6];
  int values[6];
  int i;
  if( 6 == sscanf( mac, "%x:%x:%x:%x:%x:%x%*c",&values[0], &values[1], &values[2],&values[3], &values[4], &values[5] ) ){
      /* convert to uint8_t */
      for( i = 0; i < 6; ++i )bytes[i] = (uint8_t) values[i];
  }else{
      /* invalid mac */
  } 
  return bytes;
}

wifi_set_macaddr(STATION_IF, str2mac((char*)readFileSPIFFS("/mac.txt").c_str()));
Run Code Online (Sandbox Code Playgroud)

但我在某处的代码中错了

当我AA:00:00:00:00:01输入文件时,我的ESP8266设置29:D5:23:40:00:00

我需要帮助,谢谢

c++ arduino esp8266 esp32

0
推荐指数
1
解决办法
2707
查看次数

Arduino 数组未命名类型

问题出在数组上。声明数组的那行没有问题,是它后面的那一行。似乎我无法像在 C 中那样编码。为了清晰起见,我如何在需要这种格式时修复它。我不想写很长的一行,因为这个数组中有 15 个变量。

这是代码

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

///// void setup /////
void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  delay(10);
}



///// Coordonnees /////
int angles[5][3];    //angles de chaque moteur pour chaque cube
angles[0][0]=60;
angles[0][1]=120;
angles[0][2]=100;
Run Code Online (Sandbox Code Playgroud)

基本上它angles[0][0]=;是导致问题的和与它相似的线。

c++ arrays types arduino arduino-uno

0
推荐指数
1
解决办法
2056
查看次数

如何简单地将字符串从 android studio (kotlin) 传递到 arduino 串行蓝牙模块 (HC-05)?

  • 我正在使用 Android Studio ( Kotlin )为学校项目制作一个 android 应用程序。
  • 我需要通过 HC-05 蓝牙模块将字符串发送到 Arduino Genuino Uno 模块。
  • 当应用程序启动时,Arduino 将已经连接(配对)到我的 android 设备。
  • 有人可以帮我找到一种正确且简单的方法来只发送这些数据吗?
  • 非常感谢。

android bluetooth arduino send kotlin

0
推荐指数
1
解决办法
2371
查看次数

C/C++ 中的 0b00 和 0b11 是什么意思?


我有一个小问题,希望有一个简单的答案。在 C/C++ 中对 Arduino 进行编程时,行“DDRB |= 0b00101000;” 发生。虽然我知道 DDRB 是端口 B 的数据方向寄存器以及“0b00”(即插槽 13 到 9)之后数字的含义,但我仍然不知道“0b00”是什么意思。

在定义中,我只读它意味着高(而 0b11 意味着低)但这意味着什么?

完整代码:

#include <avr/io.h>
#include <util/delay.h>

int main (void) {

  float seconds = 0.5;
  int time = 1000 * seconds;

  DDRB |= 0b00101000;

  while (1) {

    PORTB |= 0b00001000; 
    _delay_ms(time);
    PORTB &= 0b11110111; 
    PORTB |= 0b00100000;
    _delay_ms(time); 
    PORTB &= 0b11011111; 
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ arduino

0
推荐指数
1
解决办法
3260
查看次数

静态类中的向量

我想在静态类中有一个静态(常量)向量。向量不会填充新元素,它只会包含在 class configuration: 中定义的元素{1,2,3,4,5}

我怎样才能使向量debugLevels静态?

#include <ArduinoSTL.h>

class configuration {
  public:
  static std::vector<int> const debugLevels = {1,2,3,4,5}; // throws error: in-class initialization of static data member 'const std::vector<int> configuration::debugLevels' of incomplete type
};

void setup() {
  for(int i=0; i<configuration::debugLevels.size(); i++ {
    // do some stuff here...
  }
}

void loop() {
}
Run Code Online (Sandbox Code Playgroud)

c++ arduino

0
推荐指数
1
解决办法
75
查看次数

Arduino millis() - millis() 如何等于 0 以外的任何值?

所以我知道millis() 返回自程序开始运行以来经过的时间,对吗?

现在我遇到了这样的情况,在延迟中使用了 millis():

long dly = millis();
while (millis() - dly < 250) {
yield();        // enough time to send response
}
Run Code Online (Sandbox Code Playgroud)

的值怎么可能millis() - dly大于0?如果关键是无限期让步,为什么有人会使用这样的延迟?

c++ arduino arduino-ide arduino-esp8266 arduino-c++

0
推荐指数
1
解决办法
124
查看次数