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

相关文章

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Spring Shell 命令行实现交互式Shell应用开发

《SpringShell命令行实现交互式Shell应用开发》本文主要介绍了SpringShell命令行实现交互式Shell应用开发,能够帮助开发者快速构建功能丰富的命令行应用程序,具有一定的参考价... 目录引言一、Spring Shell概述二、创建命令类三、命令参数处理四、命令分组与帮助系统五、自定义S

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark