0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何训练Wekinator控制Arduino

454398 来源:工程师吴畏 2019-07-31 09:00 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

电路图

Arduino的引脚11连接到橙色LED的正极引线,通过220欧姆电阻将LED的负极引线连接到Arduino的地。类似地,通过220欧姆电阻将白色LED的正极引线连接到Arduino的引脚10和LED的负极引线连接到Arduino。

如何训练Wekinator控制Arduino

程序入门

首先,在Arduino IDE中加载下面为Arduino提供的代码。然后上传给定代码以在IDE中处理。

之后,打开Wekinator并将输入更改为1并输出为2并离开另一个选项。

点击“下一步”,会出现一个新窗口。现在从处理的输入窗口,单击橙色框,在Wekinator中,在输出-1框中输入1,然后开始录制半秒。

现在,单击处理中的白色框,在Wekinator中,在输出-1框中输入0并在输出-2框中输入1并开始记录半秒。

现在点击“Train”,然后点击“Run”。现在,当您点击橙色框时,连接到引脚11的LED将亮起,当您单击白色框时,连接到Arduino引脚10的LED将亮起。

Arduino代码

代码用注释解释。

#include //Including the library that will help us in receiving and sending the values from processing

ValueReceiver《2》 receiver; /*Creating the receiver that will receive up to 2 values.

Put the number of values to synchronize in the brackets */

/* The below two variables will be synchronized in the processing

and they should be same on both sides. */

int output;

int output1;

// Initializing the pins for led‘s

int orange_led = 11;

int white_led = 10;

void setup()

{

/* Starting the serial communication because we are communicating with the

Arduino through serial. The baudrate should be same as on the processing side. */

Serial.begin(19200);

pinMode(white_led, OUTPUT);

pinMode(orange_led, OUTPUT);

// Synchronizing the variables with the processing. The variables must be int type.

receiver.observe(output);

receiver.observe(output1);

}

void loop()

{

// Receiving the output from the processing.

receiver.sync();

// Matching the received output to light up led’s

if (output == 1)

{

digitalWrite(orange_led, HIGH);

}

else if (output == 0)

{

digitalWrite(orange_led, LOW);

}

if (output1 == 1)

{

digitalWrite(white_led, HIGH);

}

else if(output1 == 0)

{

digitalWrite(white_led, LOW);

}

}

处理代码(输入到Wekinator)

// Importing the library which will help us in communicating with the wekinator

import oscP5.*;

import netP5.*;

//creating the instances

OscP5 oscP5;

NetAddress dest;

float bx;

void setup() {

// Size of output window

size(400, 100, P3D);

// Starting the communication with wekinator. listen on port 9000, return messages on port 6448

oscP5 = new OscP5(this,9000);

dest = new NetAddress(“127.0.0.1”,6448);

}

void draw() {

// Creating the boxes in window

blocks();

// Send the OSC message to wekinator

sendOsc();

}

void mousePressed()

{

if (mouseX 》 25 && mouseX 《 75)

{

bx=1;

}

if (mouseX 》 325 && mouseX 《 375)

{

bx=2;

}

}

void sendOsc() {

OscMessage msg = new OscMessage(“/wek/inputs”);

msg.add((float)bx);

oscP5.send(msg, dest);

}

void blocks()

{

background(0);

fill(255, 155, 0);

rect(25, 25, 50, 50);

fill(255, 255, 255);

rect(325, 25, 50, 50);

}

处理代码(Wekinator的输出)

import vsync.*; // Importing the library that will help us in sending and receiving the values from the Arduino

import processing.serial.*; // Importing the serial library

// Below libraries will connect and send, receive the values from wekinator

import oscP5.*;

import netP5.*;

// Creating the instances

OscP5 oscP5;

NetAddress dest;

ValueSender sender;

// These variables will be syncronized with the Arduino and they should be same on the Arduino side.

public int output;

public int output1;

void setup()

{

// Starting the serial communication, the baudrate and the com port should be same as on the Arduino side.

Serial serial = new Serial(this, “COM10”, 19200);

sender = new ValueSender(this, serial);

// Synchronizing the variables as on the Arduino side. The order should be same.

sender.observe(“output”);

sender.observe(“output1”);

// Starting the communication with wekinator. listen on port 12000, return messages on port 6448

oscP5 = new OscP5(this, 12000);

dest = new NetAddress(“127.0.0.1”, 6448);

}

// Recieve OSC messages from Wekinator

void oscEvent(OscMessage theOscMessage) {

if (theOscMessage.checkAddrPattern(“/wek/outputs”) == true) {

// Receiving the output from wekinator

float value = theOscMessage.get(0).floatValue(); // First output

float value1 = theOscMessage.get(1).floatValue(); // Second output

// Converting the output to int type

output = int(value);

output1 = int(value1);

}

}

void draw()

{

// Nothing to be drawn for this example

}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • Arduino
    +关注

    关注

    190

    文章

    6515

    浏览量

    195964
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    Arduino plc和termux esp

    Arduino plc和termux esp
    的头像 发表于 12-06 06:41 1159次阅读

    如何在 NuMaker-IoT-M467 板上使用 Arduino IDE 控制 Wi-Fi 模块?

    在NuMaker开发板上,有一个ESP-12F Wi-Fi模块;但是,Arduino IDE 中的 NuMaker UNO 包不提供该模块的相关控制。如果您希望在 Arduino IDE 中
    发表于 09-04 08:28

    使用 ai cude 里面自带的案例训练UI显示异常的原因?怎么解决?

    案例的配置是默认的,显示训练ui更改显示异常
    发表于 06-23 06:21

    Arduino与LabVIEW联合编程指南

    Arduino编程并与LabVIEW上位机结合实现设备的远程控制与数据采集。
    发表于 06-19 15:54 1次下载

    k210在线训练的算法是yolo5吗?

    k210在线训练的算法是yolo5吗
    发表于 06-16 08:25

    OCR识别训练完成后给的是空压缩包,为什么?

    OCR识别 一共弄了26张图片,都标注好了,点击开始训练,显示训练成功了,也将压缩包发到邮箱了,下载下来后,压缩包里面是空的 OCR图片20几张图太少了。麻烦您多添加点,参考我们的ocr识别训练数据集 请问
    发表于 05-28 06:46

    免费分享Arduino入门+进阶(全套例程+书籍)

    创意,比如控制灯光、传感器、电机等。以下是Arduino入门+进阶学习资料1.Arduino编程语言说明(相关文件可在下文扫码领取)2.Arduino系列学习例程
    的头像 发表于 05-22 11:40 783次阅读
    免费分享<b class='flag-5'>Arduino</b>入门+进阶(全套例程+书籍)

    《ESP32S3 Arduino开发指南》第二章 Arduino基础知识

    的发展,在Arduino出现以前,虽然也有很多公司在推广一些简单易用的可编程控制器,但是由于开发平台种类繁多,而且使用这些控制器基本上都需要对电子技术、数字逻辑、寄存器等内容进行多方面的了解和学习,才能
    发表于 05-13 09:28

    请问训练平台训练完的识别程序,可以实现在识别到物体时屏幕再显示出来,没有识别到物体时屏幕不显示吗?

    问题如题,训练平台训练完的识别程序,可以实现在识别到物体时屏幕再显示出来,没有识别到物体时屏幕不显示吗?比较小白,可以解释一下怎么做吗?或者是我应该学哪里? 如果直接使用平台下载的代码不行,改一改可以。
    发表于 04-29 06:12

    海思SD3403边缘计算AI数据训练概述

    AI数据训练:基于用户特定应用场景,用户采集照片或视频,通过AI数据训练工程师**(用户公司****员工)** ,进行特征标定后,将标定好的训练样本,通过AI训练服务器,进行AI学习
    发表于 04-28 11:11

    训练好的ai模型导入cubemx不成功怎么处理?

    训练好的ai模型导入cubemx不成功咋办,试了好几个模型压缩了也不行,ram占用过大,有无解决方案?
    发表于 03-11 07:18

    华为公布AI模型训练与车辆控制专利

    近日,华为技术有限公司在技术创新领域再次迈出重要一步,其申请的“模型的训练方法、车辆的控制方法及相关装置”专利于2月18日正式公布。这一专利的公布标志着华为在人工智能领域的又一重大突破。 据专利摘要
    的头像 发表于 02-20 09:14 725次阅读

    大模型训练框架(五)之Accelerate

    Hugging Face 的 Accelerate1是一个用于简化和加速深度学习模型训练的库,它支持在多种硬件配置上进行分布式训练,包括 CPU、GPU、TPU 等。Accelerate 允许用户
    的头像 发表于 01-14 14:24 1767次阅读

    如何使用Arduino实现CAN总线通信呢

    CAN(Controller Area Network)总线是一种常用于汽车和工业控制系统的串行通信协议,以其高可靠性和实时性而闻名。Arduino,作为一种流行的开源微控制器平台,可以通过附加
    的头像 发表于 12-23 09:06 2817次阅读

    GPU是如何训练AI大模型的

    在AI模型的训练过程中,大量的计算工作集中在矩阵乘法、向量加法和激活函数等运算上。这些运算正是GPU所擅长的。接下来,AI部落小编带您了解GPU是如何训练AI大模型的。
    的头像 发表于 12-19 17:54 1322次阅读