0

我需要帮助构建一个“简单”的 arduino 代码来传输和接收 IR 信号。

我尝试了互联网上的几个代码,但没有一个适合我的 Logarex 电表。喜欢: http ://tunn.us/arduino/landisgyr.php https://github.com/prophetmaster/landisgyre350

通信由 IEC 62056-21 完成。我正在尝试向我的电表发送握手 0x2F, 0x3F, 0x21.0x0D, 0x0A 然后请求数据 0x06.0x30.0x35.0x30.0x0D, 0x0A 收入 不幸的是,我无法获得任何信息。通过红外发射器发送握手,然后请求数据,然后开始在红外接收器上接收数据是否容易?我是否需要以 300 波特率进行握手,然后在下一部分以 9600 通信并在 IR RX 中接收 9600?

The output should be something like this on an arduino serial monitor.

Baudrate: 300 bps, 7 bits, parity even, 1 stop bit
Send:     /?!<CR><LF>         (wake-up and sign-on)
Receive:  /XXX5YYYYY<CR><LF>  (XXX is the manufacturer ID; YYYYY is the meter ID; 5 is the new baudrate = 9600 bps)
Send:     <ACK>050<CR><LF>    (send ack; reading mode)
Baudrate: 9600 bps, 7 bits, parity even, 1 stop bit
Received: C.1(201236731.0(01:39 25-08-18)
      1.8.1(0004398506*Wh)
      1.8.2(0000000000*Wh)
      1.8.3(0008198809*Wh)
      1.8.4(0000000000*Wh)
      1.8.5(0000000000*Wh)
      1.8(0012597315*Wh)
      2.8(0000000000*Wh)
      !
      D

谢谢大家的帮助,我是初学者,对IR没有经验。

4

1 回答 1

0

如果您使用的是 arduino uno,标准库不支持初始查询所需的 7E1。为此,您必须编写自己的 uart 驱动程序。

你需要写接收部分,我在给出想法方面分享它。

//Description video : https://www.youtube.com/watch?v=2s4W6sOT0mU
typedef struct uconfig
{ 
  uint32_t  baud;
  uint8_t  _UBRR0H;
  uint8_t  _UBRR0L;
  uint8_t  _UCSR0B;
  uint8_t  _UCSR0C;
} baud_registers;

/*
 * How can i calculate _UBRROH and _UBRR0L. Here is the cpp script.
 * You need to check the atmega328p datasheet to understand
 * 
#include <iostream>
#define BAUDRATE 300
#define _UBRR (((16000000 / (BAUDRATE * 16UL))) - 1)
int main()
{
  int msb= ((_UBRR) & 0xF00);
  int lsb = ((_UBRR) & 0xFF);
  if(msb>256)
  {
      msb= msb>>8;
  }
  std::cout<<"msb: " << msb;
  std::cout<<"\n";
  std::cout<<"lsb : "<<lsb;

}
 * 
 * 
 */
static const uconfig  baud_table[]= {
  {300,0x0D,0x04,0x18,0x24},
};

int uart_init(uint32_t baudRate_u32)
{
  int status=0;
  uint8_t i=0;
  for( i=0; i< sizeof(baud_table)/sizeof(baud_table[0]); i++)
   {
    if(baud_table[i].baud == baudRate_u32)
    {
       break;
    }
   }

   if( i < sizeof(baud_table)/sizeof(baud_table[0])) {
    UBRR0H=baud_table[i]._UBRR0H;
    UBRR0L=baud_table[i]._UBRR0L;
    UCSR0B=baud_table[i]._UCSR0B;
    UCSR0C=baud_table[i]._UCSR0C;
    status=1;

   }
   return status;

}

void USART_transmit( unsigned char data ) {
    while(!(UCSR0A & (1 << UDRE0)));
    UDR0 = data;
}

void setup() {
  while(!uart_init(300));
}

void loop() {
  USART_transmit('a');
  delay(1000);
}

另外,在我的论文中,我研究了电表读数。我使用 Arduino mega 进行了阅读。

于 2019-10-11T10:29:10.687 回答