首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用seeed的Arduino Canbus屏蔽将Canbus命令写入键盘

使用seeed的Arduino Canbus屏蔽将Canbus命令写入键盘
EN

Stack Overflow用户
提问于 2021-06-20 07:01:49
回答 1查看 160关注 0票数 0

所以我在我的arduino uno上使用了我的seeed studio canbus盾牌。我有两个目标,第一个是从键盘读取数据,第二个是向键盘写入命令,使LED灯改变颜色并关闭和打开。我能够使用seeed代码轻松地从控制器读取数据,但我不知道如何将我的命令发送到键盘。

下面是我使用的代码,也来自seed studio库

代码语言:javascript
运行
复制
#include <SPI.h>

#define CAN_2515
// #define CAN_2518FD

// Set SPI CS Pin according to your hardware

#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)
// For Wio Terminal w/ MCP2518FD RPi Hat:
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
const int SPI_CS_PIN  = BCM8;
const int CAN_INT_PIN = BCM25;
#else

// For Arduino MCP2515 Hat:
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#endif


#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#endif

#ifdef CAN_2515
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif

void setup() {
    SERIAL_PORT_MONITOR.begin(250000);
    while(!Serial){};

    while (CAN_OK != CAN.begin(CAN_250KBPS)) {             // init can bus : baudrate = 250k
        SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
        delay(100);
    }
    SERIAL_PORT_MONITOR.println("CAN init ok!");
}

unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void loop() {
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf
    stmp[7] = stmp[7] + 1;
    if (stmp[7] == 100) {
        stmp[7] = 0;
        stmp[6] = stmp[6] + 1;

        if (stmp[6] == 100) {
            stmp[6] = 0;
            stmp[5] = stmp[5] + 1;
        }
    }

    CAN.sendMsgBuf(0x00, 0, 8, stmp);
    delay(100);                       // send data per 100ms
    SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
}

// END FILE

Here is a copy of the commands I am trying to send to the keypad, the commands come from the documentation I got with the keypad

EN

回答 1

Stack Overflow用户

发布于 2021-10-08 09:42:58

您附加的can矩阵显示键盘的ID为215,很可能是0x215 (十六进制),并且您正在发送ID为0x00的消息。键盘对此没有响应。

将发送消息更改为:

代码语言:javascript
运行
复制
    CAN.sendMsgBuf(0x215, 0, 8, stmp);

CAN是一种基于ID优先级的协议,ID越低,优先级越高。较小的数字用于关键消息,如错误和故障。根据经验,不使用ID 0x00。

现在,根据您希望看到的颜色,您必须将适当的值放在stmp数组中

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68051376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档