Tag: arduino

如何在Arduino串口打印AT命令的响应?

我想打印AT命令的响应。 我正在发送AT命令,但我没有在Arduino串口中得到任何响应。 它给-1而不是OK。 #include “SoftwareSerial.h” String ssid = “connectify-krish”; String password = “12345678”; String myword= “”; SoftwareSerial esp(10, 11); void setup() { Serial.begin(9600); esp.begin(9600); esp.write(“AT”); Serial.println(esp.read()); } void loop() {}

使用Visual Studio 2008和C进行串行通信(适用于Arduino)

我想使用Visual Studio和C将数据发送到我的Arduino板。我特别需要使用C,因为我使用ARToolKit获取标记并相应地发送数据。 我正在尝试代码 #include #include void main() { system( “MODE COM9: BAUD=9600 PARITY=n DATA=8 STOP=1” ) ; FILE port = fopen( “COM9:”, “wb” ) ; printf(“hello”); fprintf( port, “s” ) ; fclose( port ) ; } 但它没有得到编译。 我只需要发送数据。

Arduino传感器10DOF MPU9255无法获取磁力计数据

我正在使用带有MPU9255和BMP180的10 DOF IMU来收集方向数据。 当我为arduino运行草图时,我下载它来测试IMU的function,它可以完美地收集来自加速度计和陀螺仪元素的数据,但是它仍然无法从磁力计请求数据,而这种数据从未接收过。 它成功读取磁力计数据一次,但除非我重新上传程序,否则再也无法读取它。 更具体地说,按位并且从不评估为真,因此程序无法继续,因为数据从磁力计“未准备好”。 令人讨厌的代码行是这样的: do { I2Cread(MAG_ADDRESS,0x02,1,&ST1); } while (!(ST1&0x01)); 但这是完整的代码,以防万一 #include #define MPU9250_ADDRESS 0x68 #define MAG_ADDRESS 0x0C #define GYRO_FULL_SCALE_250_DPS 0x00 #define GYRO_FULL_SCALE_500_DPS 0x08 #define GYRO_FULL_SCALE_1000_DPS 0x10 #define GYRO_FULL_SCALE_2000_DPS 0x18 #define ACC_FULL_SCALE_2_G 0x00 #define ACC_FULL_SCALE_4_G 0x08 #define ACC_FULL_SCALE_8_G 0x10 #define ACC_FULL_SCALE_16_G 0x18 // This function read Nbytes bytes from I2C device at […]

什么时候全局变量的初始化发生?

我知道程序运行时,首先执行main()函数。 但是什么时候在main()之外声明的全局变量的初始化发生了? 我的意思是如果我声明一个这样的变量: unsigned long current_time = millis(); void main() { while () { //some code using the current_time global variable } } 这里,全局变量初始化的确切时间很重要。 请告诉我在这种情况下会发生什么。

字符串到Arduino中的const char *?

我有一个变量tweet ,它是一个字符串,它在一开始就有一个字符我要剪掉。 所以我想要做的是使用strstr()来删除它。 这是我的代码: tweet = strstr(tweet, “]”); 但是,我收到此错误: cannot convert ‘String’ to ‘const char*’ for argument ‘1’ to ‘char’ strstr(const char*, const char*) 所以我的想法是将tweet转换为char。 我该怎么做呢?

printf的包装

我在Arduino下编码,我想开发串行打印格式化function,所以我试图使用未知大小的缓冲区的sprintf 。 基本上,我们可以避免谈论Arduino及其串行输出,并考虑将文本写入缓冲区然后使用printf打印它。 我试过这个: #include #include void printf0( const char* format, … ) { va_list args; va_start(args, format); vprintf(format, args); va_end( args ); } void printf1(const char* format,…) { va_list args; va_start(args, format); char buf[vsnprintf(NULL, 0, format, args)]; sprintf(buf, format, args); printf(buf); va_end(args); } int main() { printf0(“Hello, %d!\n”, 15); printf1(“Hello, %d!\n”, 15); return 0; […]

许多客户端打印后,Arduino(Uno)以太网客户端连接失败

我正在使用带有以太网盾的Arduino Uno。 发送许多HTTP请求后, client.println(…) ,连接时客户端开始失败。 失败的时间似乎是随机的,并且循环的序列读数可以在~1000到~7000之间的任何地方变化。 该错误与以太网发送缓冲区溢出无关(遵循此建议 ) 这是失败的代码: #include #include // Network constants byte mac[] = {0x00, 0x23, 0xdf, 0x82, 0xd4, 0x01}; byte ip[] = {/*REDACTED*/}; byte server[] = {/*REDACTED*/}; int port = /*REDACTED*/; Client client(server, port); // State int sequence; void setup(){ Ethernet.begin(mac, ip); Serial.begin(9600); sequence = 0; delay(1000); } void loop(){ httpPut(“/topic/:test/publish?sessionId=SESenanhygrp”); […]

字符串引用未在C ++中的函数调用中更新

我正在写一个arduino库来在网上发布http请求。 我正在使用http://arduino.cc/en/Tutorial/TextString中的String类 当我在函数调用后引用我定义的字符串对象时,我的代码表现得很奇怪。 实际上,我试图获取我的GET请求的主体并从http GET请求的响应中删除http标头。 以下是描述: 方法调用: String body; if(pinger.Get(host,path,&body)) { Serial.println(“Modified String Outside :”); Serial.println(body); Serial.println(); Serial.println(“Modified String Outside Address”); Serial.println((int)&body); } 产量 Modified String Outside : HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html Content-Length: 113 Date: Wed, 13 Jan 2010 14:36:28 GMT Ashish Sharma Wed Jan 13 20:06:28 IST 2010 Modified String Outside […]

如何从两个字节组装一个浮点数?

我目前正在开展一个项目,我需要读出DHT11湿度和温度传感器 。 MCU和串行设备之间的通信非常低级,但我设法接收测量值(湿度+温度)作为长度为4的字节数组(第5个字节是校验和): 我从DHT11传感器收到的值: – byte[0] = humidity integer part – byte[1] = humidity decimal part – byte[2] = temperature integer part – byte[3] = temperature decimal part – byte[4] = checksum of the first four bytes 我现在想将byte[0]和byte[1]转换为float ,温度相同(byte [2]和byte [3])。 在C / C ++的Arduino Mega 2560上实现这一目标的有效方法是什么? 例: byte[0] = 20 and byte[1] = 12 […]

arduino和visual studio c ++,2路串行通信

我正在使用Arduino和Visual studio c ++并尝试构建双向实时串行通信。 我正在使用的是win 10(在VMware Fusion中),32位系统,visual studio 2013,Arduino IDE 1.8.0和Arduino板Uno。 我使用了http://playground.arduino.cc/Interfacing/CPPWindows中的库文件,它们是两个文件: SerialClass.h和Serial.cpp。 我在我的主要使用readData()和WriteData()函数。 我想再运行几次,用户可以在控制台中输入,Arduino会相应地生成输出。 但是当我添加while循环时,它无法正常工作。 下面是我的main.cpp :(在注释行中使用while循环) int main() { Serial* port = new Serial(“COM3”); if (port->IsConnected()) cout << "Connected!" << endl; char data[4] = ""; char command[2] = ""; int datalength = 4; //length of the data, int readResult = 0; int n; […]