8266 Ubuntu下 arduino开发

2024-04-13 10:20
文章标签 ubuntu 开发 arduino 8266

本文主要是介绍8266 Ubuntu下 arduino开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

8266 NodeMCU arduino开发

直接用usb连接8266的usb接口即可,设备中会出现/dev/ttyUSB0, 需要将其权限设置下sudo usermod -a -G dialout $USER. logout后生效.
下载arduino IDE,做以下设置:

  • file/preferences Additional boards manager URLS设置为http://arduino.esp8266.com/stable/package_esp8266com_index.json
  • Tools//Board设置为NodeMCU 1.0(ESP-12E Module)
  • Tools/Port设置为/dev/ttyUSB0
    编写下面代码
#define LED_BUILTIN 2
int i_frame = 0;
void setup() {   Serial.begin(9600);         // Start the Serial communication to send messages to the computerdelay(1);Serial.println("init done \n");// initialize inbuilt LED pin as an output.pinMode(LED_BUILTIN, OUTPUT);
}// loop function runs over and over  again forever
void loop() {char buff[255];sprintf(buff, "%d frame------", i_frame);Serial.println(buff);// Serial.print(i_frame);// Serial.println("loop----");digitalWrite(LED_BUILTIN, HIGH);   // turn the  LED on by making the pin 13 HIGHdelay(500);              // wait for a 0.5  seconddigitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the  pin 13 LOWdelay(500);              // wait for a 0.5 secondi_frame += 1;
}

点击upload即可.

注意

arduino esptool 可能会比较老导致刷入固件失败,那么可以用pip安装一个最新的版本,然后替换掉arduino用的这个版本.

pip install esptool
# 查看新安装的版本位置
pip show esptool
cd ~/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools
mv esptool esptool_ori
cp ~/anaconda3/lib/python3.7/site-packages/esptool . -r

重新build即可.

  • 其他一些命令
# 获取flash信息
esptool.py --port /dev/ttyUSB0  --baud 115200 flash_id# 手动刷入bin
esptool.py --port /dev/ttyUSB0  --baud 115200 write_flash -fm dio 0x00000 ./0x00000.bin

mqtt示例

  • 先安装mqtt 库
    Sketch -> Include Library -> Manage Libraries… 输入PubSubClient, 选择Nick O’Leary版本
  • 下载MQTTX
    配置:
    Broker: broker.emqx.io
    TCP Port: 1883
    Websocket Port: 8083
  • 使用以下代码测试
#include <ESP8266WiFi.h>
#include <PubSubClient.h>// WiFi
const char *ssid = "2.4g"; // Enter your WiFi name
const char *password = "abc";  // Enter WiFi password// MQTT Broker
const char *mqtt_broker = "broker.emqx.io";
const char *topic = "esp8266/test";
const char *mqtt_username = "emqx";
const char *mqtt_password = "public";
const int mqtt_port = 1883;WiFiClient espClient;
PubSubClient client(espClient);void setup() {// Set software serial baud to 115200;Serial.begin(115200);// connecting to a WiFi networkWiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.println("Connecting to WiFi..");}Serial.println("Connected to the WiFi network");//connecting to a mqtt brokerclient.setServer(mqtt_broker, mqtt_port);client.setCallback(callback);while (!client.connected()) {String client_id = "esp8266-client-";client_id += String(WiFi.macAddress());Serial.printf("The client %s connects to the public mqtt broker\n", client_id.c_str());if (client.connect(client_id.c_str(), mqtt_username, mqtt_password)) {Serial.println("Public emqx mqtt broker connected");} else {Serial.print("failed with state ");Serial.print(client.state());delay(2000);}}// publish and subscribeclient.publish(topic, "hello emqx");client.subscribe(topic);
}void callback(char *topic, byte *payload, unsigned int length) {Serial.print("Message arrived in topic: ");Serial.println(topic);Serial.print("Message:");for (int i = 0; i < length; i++) {Serial.print((char) payload[i]);}Serial.println();Serial.println("-----------------------");
}void loop() {client.loop();
}
  • 在mqttx中输入message后,arduino 串口会打印出消息.

12F 接线参考

https://blog.csdn.net/qq_42190295/article/details/91867943
https://zhuanlan.zhihu.com/p/346356668

fm的设置参考官方解释:

flash-mode is qio for most ESP8266 ESP-01/07 (512 kByte modules) and dio for most ESP32 and ESP8266 ESP-12 (>=4 MByte modules). ESP8285 requires dout.
其他资料:
https://www.dfrobot.com.cn/images/upload/File/DFR0489/20170906115748b3idk3.pdf

这篇关于8266 Ubuntu下 arduino开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/899871

相关文章

如何在Ubuntu 24.04上部署Zabbix 7.0对服务器进行监控

《如何在Ubuntu24.04上部署Zabbix7.0对服务器进行监控》在Ubuntu24.04上部署Zabbix7.0监控阿里云ECS服务器,需配置MariaDB数据库、开放10050/1005... 目录软硬件信息部署步骤步骤 1:安装并配置mariadb步骤 2:安装Zabbix 7.0 Server

Ubuntu如何分配​​未使用的空间

《Ubuntu如何分配​​未使用的空间》Ubuntu磁盘空间不足,实际未分配空间8.2G因LVM卷组名称格式差异(双破折号误写)导致无法扩展,确认正确卷组名后,使用lvextend和resize2fs... 目录1:原因2:操作3:报错5:解决问题:确认卷组名称​6:再次操作7:验证扩展是否成功8:问题已解

SpringBoot开发中十大常见陷阱深度解析与避坑指南

《SpringBoot开发中十大常见陷阱深度解析与避坑指南》在SpringBoot的开发过程中,即使是经验丰富的开发者也难免会遇到各种棘手的问题,本文将针对SpringBoot开发中十大常见的“坑... 目录引言一、配置总出错?是不是同时用了.properties和.yml?二、换个位置配置就失效?搞清楚加

Python中对FFmpeg封装开发库FFmpy详解

《Python中对FFmpeg封装开发库FFmpy详解》:本文主要介绍Python中对FFmpeg封装开发库FFmpy,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、FFmpy简介与安装1.1 FFmpy概述1.2 安装方法二、FFmpy核心类与方法2.1 FF

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

基于Python开发一个有趣的工作时长计算器

《基于Python开发一个有趣的工作时长计算器》随着远程办公和弹性工作制的兴起,个人及团队对于工作时长的准确统计需求日益增长,本文将使用Python和PyQt5打造一个工作时长计算器,感兴趣的小伙伴可... 目录概述功能介绍界面展示php软件使用步骤说明代码详解1.窗口初始化与布局2.工作时长计算核心逻辑3