Regarding rmt_tx library to transmit rawData to Mitsubishi AC

sam_wesleyIcapo
Posts: 4
Joined: Fri Sep 18, 2020 6:00 am

Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby sam_wesleyIcapo » Fri Sep 18, 2020 6:07 am

Hi,
This is the code used for transmitting rawData to the Mitsubishi AC using esp-idf:
Mitubishi_tx.c:
* NEC remote infrared RMT example

This example code is in the Public Domain (or CC0 licensed, at your option.)

Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/ringbuf.h"
#include "esp_err.h"
#include "esp_log.h"
#include "driver/rmt.h"
#include "driver/periph_ctrl.h"
#include "soc/rmt_reg.h"
//int rawData[512]={3379,-1661,443,-1237,435,-1246,437,-403,438,-402,439,-401,441,-1239,443,-397,445,-395,436,-1245,437,-1243,440,-400,442,-1238,444,-396,435,-406,436,-1244,438,-1242,441,-399,442,-1238,435,-1246,437,-403,438,-402,439,-1241,442,-398,443,-397,445,-1236,436,-404,437,-403,439,-401,440,-400,441,-399,443,-397,444,-396,435,-405,437,-404,437,-403,438,-402,440,-400,441,-399,442,-398,444,-396,435,-405,436,-405,437,-403,438,-402,439,-401,441,-399,442,-398,444,-396,435,-405,436,-405,436,-404,438,-1242,440,-1240,443,-397,444,-396,435,-405,437,-1244,438,-1242,441,-1239,444,-396,435,-405,436,-405,437,-403,27876,16379,27408,16379,1104,22593,10612,16379,15264,16379,27520,16379,0,0,20,0,-30106,21106,15491,-13113,27520,16379,0,0,5,0,26748,16379,28772,29295,116,-12996,-16757,-2030,-22319,191,1,0,27512,16379,0,0,33,6,5,0,0,0,0,0,0,0,0,0,-26800,16378,-26904,16378,-27008,16378,0,0,0,0,1,0,0,0,11020,16192,0,0,7496,16384,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-21248,-10458,-32761,16381,-32760,16381,-32750,17586,20623,5485,18228,17283,-28985,6209,32766,20757,-19497,13714,10505,-15309,13323,-1751,5684,-2195,20760,-13644,-13039,10118,-9632,1374,2141,31530,-13234,17362,14740,24452,27814,-9606,6861,17286,-17868,-27523,-13463,-20790,-12961,13269,-31556,-10883,-16326,20923,21393,31394,-2046,31646,14755,-23511,31183,442,18068,-18165,28076,16379,27996,16379,27996,16379,27996,16379,27996,16379,0,0,28020,16379,-32767,-32767,28020,16379,28020,16379,0,0,28040,16379,-32767,-32767,28040,16379,28040,16379,1,0,1,0,0,0,0,0,-32767,-13119,0,0,28160,16379,28080,16379,28080,16379,28080,16379,28080,16379,0,0,28104,16379,-32767,-32767,28104,16379,28104,16379,0,0,28124,16379,-32767,-32767,28124,16379,28124,16379,0,0,1,0,0,0,0,0,-32767,-13119,0,0,28244,16379,0,0,0,0,28164,16379,0,0,0,0,28188,16379,-32767,-32767,28188,16379,28188,16379,0,0,28208,16379,-32767,-32767,28208,16379,28208,16379,1,0,1,0,0,0,0,0,-32767,-13119,0,0,28260,16379,8,3034,0,0,-32700,16378,30312,16379,-9637,-9637,-9637,-9637,-9637,-9637,-9637,-9637,-9637,-9637,-9637,-9637};
void rx_channels_init();
void visible_led_init();
void rmt_example_nec_rx_task();
/******************************************************/
/***** SELF TEST: *****/
/*Connect RMT_TX_GPIO_NUM with RMT_RX_GPIO_NUM */
/*TX task will send NEC data with carrier disabled */
/*RX task will print NEC data it receives. */
/******************************************************/
//Test with infrared LED, we have to enable carrier for transmitter
//When testing via IR led, the receiver waveform is usually active-low.
#define RMT_TX_CARRIER_EN 1 /*!< Enable carrier for IR transmitter test with IR led */


#define RMT_RX_CHANNEL 0 /*!< RMT channel for receiver */
#define RMT_RX_GPIO_NUM 19 /*!< GPIO number for receiver */

#define RMT_TICK_10_US (80000000/RMT_CLK_DIV/100000) /*!< RMT counter value for 10 us.(Source clock is APB clock) */
#define RMT_TX_DATA_NUM 100 /*!< NEC tx test data number */
#define rmt_item32_tIMEOUT_US 9500 /*!< RMT receiver timeout value(us) */

/*
* @brief RMT transmitter initialization
*/


void app_main()
{
rx_channels_init();
visible_led_init();
// start receive processing task

xTaskCreate(rmt_example_nec_rx_task, "rmt_nec_rx_task", 8192, NULL, 10, NULL);
}

rmt_rx_Daikin.c:
/* RMT receive example, displaying raw RMT data
*
* This code was adapted from example: rmt_nec_tx_rx
* That software is distributed under Public Domain (or CC0 licensed, at your option.)
*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
*
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "esp_err.h"
#include "esp_log.h"
#include "driver/rmt.h"
#include "driver/periph_ctrl.h"
#include "soc/rmt_reg.h"
#include <math.h>
// FreeRTOS function
#define INCLUDE_vTaskDelay 1
#define RMT_TX_CHANNEL 1 /*!< RMT channel for transmitter */
#define RMT_TX_GPIO_NUM 18 /*!< GPIO number for transmitter signal */
#define RMT_CLK_DIV 100 /*!< RMT counter clock divider */
void rmt_example_nec_tx_task();
#define rrmt_item32_tIMEOUT_US 9500 /*!< RMT receiver timeout value */
int rawData1[512];
// LED on Huzzah32 board
const int LED_BUILTIN = 13;
// structure used to initialize RMT inputs
// NOTE: tag is used on the monitor outputs to distinguish between channels
struct rmt_rx_inits {
rmt_channel_t channel;
gpio_num_t gpio_num;
uint8_t clk_div;
uint8_t mem_block_num;
bool config_filter_en;
uint8_t config_filter_tics_thresh;
uint16_t config_idle_threshold;
char tag[10];
}rx_inputs[1] = {
//{ 0, 21, 80, 1, false, 0, 50000, "Ch0" },
{ 0, 19, 80, 1, false, 0, 50000, "Ch0" }
};

// initialize RMT receive channels
void rx_channels_init() {
rmt_config_t rmt_rx;
size_t i;
size_t len = sizeof(rx_inputs) / sizeof( rx_inputs[0] );
for ( i=0; i<len; i++ ) {
rmt_rx.channel = rx_inputs.channel;
rmt_rx.gpio_num = rx_inputs.gpio_num;
rmt_rx.clk_div = rx_inputs.clk_div;
rmt_rx.mem_block_num = rx_inputs.mem_block_num;
rmt_rx.rmt_mode = RMT_MODE_RX;

rmt_rx.rx_config.filter_en = rx_inputs.config_filter_en;
rmt_rx.rx_config.filter_ticks_thresh = rx_inputs.config_filter_tics_thresh;
rmt_rx.rx_config.idle_threshold = rx_inputs.config_idle_threshold;

rmt_config(&rmt_rx);
rmt_driver_install(rx_inputs.channel, 1000, 0);
}
}
void nec_tx_init()
{
rmt_config_t rmt_tx;
rmt_tx.channel = RMT_TX_CHANNEL;
rmt_tx.gpio_num = RMT_TX_GPIO_NUM;
rmt_tx.mem_block_num = 7;
rmt_tx.clk_div = RMT_CLK_DIV;
rmt_tx.tx_config.loop_en = false;
rmt_tx.tx_config.carrier_duty_percent = 25;
rmt_tx.tx_config.carrier_freq_hz = 38000;
rmt_tx.tx_config.carrier_level = 1;
rmt_tx.tx_config.carrier_en = false;
rmt_tx.tx_config.idle_level = 0;
rmt_tx.tx_config.idle_output_en = true;
rmt_tx.rmt_mode = 0;
rmt_config(&rmt_tx);
rmt_driver_install(rmt_tx.channel, 0, 0);
}
/**
* @brief RMT transmitter demo, this task will periodically send NEC data. (100 * 32 bits each time.)
*
*/
void rmt_example_nec_tx_task()
{
vTaskDelay(10);
nec_tx_init();
int channel = RMT_TX_CHANNEL;
//size_t size = (sizeof(rmt_item32_t) * 256);
//each item represent a cycle of waveform.
// rmt_item32_t* item = (rmt_item32_t*) malloc(size);
rmt_item32_t item[256];
int item_num = 256;
//memset((rmt_item32_t*) item, 0, size);
int i, t;
RingbufHandle_t rb;
for(i=0,t=0;i<512;i=i+2,t=t+1)
{
item[t].level0 = 1;
item[t].duration0 = (int)abs(rawData1);
item[t].level1 = 0;
item[t].duration1 = (int)abs(rawData1[i+1]);
}
//To send data according to the waveform items.
rmt_write_items(channel, item, 256, true);
//Wait until sending is done.
rmt_wait_tx_done(channel,1);
//before we free the data, make sure sending is already done.
//free(item);
vTaskDelay(5000 / portTICK_PERIOD_MS);
//rmt_tx_stop(channel);
vTaskDelete(NULL);
}
// initialize visible LED on ESP32 board
void visible_led_init() {
gpio_pad_select_gpio(LED_BUILTIN);
gpio_set_direction(LED_BUILTIN, GPIO_MODE_OUTPUT);
}

/* Converts the RMT level, duration into a positive or negative integer
* Compatible with the ESP32-RMT-server application
* Note: most IR receivers have active-low outputs, where the
* ESP32-RMT-server application has active-high oututs
* This function inverts the RMT receive level so the text output is
* compatible with ESP32-RMT-server application
*/
int dur( uint32_t level, uint32_t duration ) {
if ( level == 0 ) { return duration; }
else { return -1.0 * duration; }
}
static void receive_decode()
{
char c[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int output[128];
char out[32];
int k=0;
for(int i=2;i<256;i+=2,k++)
if((abs(rawData1)>1000)||(abs(rawData1[i+1])>1000))
{
output[k]=1;
}
else
{
output[k]=0;
//printf("%d",output[i-2]);
}
//printf("\n");
int t=0;
int length=k;
char Power[4];
int Temperature;
char Mode[5];
char FanSpeed[8];
for(int i=0;i<length;)
{
int check=0;
int power;
for(int j=i,k=0;(j<(i+4))&&(j<127);k++,j++)
{
check=check+(int)pow(2,3-k)*output[j];
}
i=i+4;
out[t]=c[check];
t=t+1;
}
for(int i=0;i<32;i++)
printf("%c",out[i]);
printf("\n");
Temperature=16+8*output[59]+4*output[58]+2*output[57]+output[56];
if(out[11]=='0')
strcpy(Power,"Off");
else
{
strcpy(Power,"On");
if(out[18]=='A'||out[18]=='D')
strcpy(FanSpeed,"Listen");
else if(out[18]=='1')
strcpy(FanSpeed,"Low");
else if(out[18]=='3'||out[18]=='C')
strcpy(FanSpeed,"Med");
else if(out[18]=='6'||out[18]=='4')
strcpy(FanSpeed,"High");
else if(out[18]=='2'||out[18]=='0')
strcpy(FanSpeed,"Highest");
else if(out[18]=='1')
strcpy(FanSpeed,"Auto");
if(out[13]=='8' && out[12]=='1')
strcpy(Mode,"Cool");
else if(out[13]=='8' && out[12]=='0')
strcpy(Mode,"Dry");
else if(out[13]=='0')
strcpy(Mode,"Auto");
else if(out[13]=='C')
strcpy(Mode,"Fan");
printf("FanSpeed=%s\n",FanSpeed);
printf("Mode=%s\n",Mode);
printf("Temperature=%d\n",Temperature);
}
printf("Power=%s\n",Power);
return;
}
// RMT receiver task
void rmt_example_nec_rx_task() {
size_t num_channels = sizeof(rx_inputs) / sizeof( rx_inputs[0] );
size_t c, i,t;
size_t rx_size = 0;
rmt_item32_t* items = NULL;
// define ringbuffer handle
RingbufHandle_t rb;
// start receiving IR data
for ( c=0; c<num_channels; c++ ) {
rmt_rx_start(rx_inputs[c].channel, 1);
}
while(1)
{
// loop forever
for(i=0;i<512;i++)
rawData1[i]=0;
// check each receive channel
for ( c=0; c<num_channels; c++ ) {
// get the ring buffer handle
rmt_get_ringbuf_handle(rx_inputs[c].channel, &rb);
// get items, if there are any
items = (rmt_item32_t*) xRingbufferReceive(rb, &rx_size, 1000);
if(items) {
// turn on visible led
gpio_set_level(LED_BUILTIN, 1);

// print the RMT received durations to the monitor
printf( " %s received %i items\n", rx_inputs[c].tag, 256 );
for ( i=0,t=0; i<256; i++ ) {
if ( i>0 ) { printf(","); }
rawData1[t]=dur( items[i].level0, items[i].duration0 );
rawData1[t+1]=dur( items[i].level1, items[i].duration1 );
t=t+2;
printf( "%i", dur( items[i].level0, items[i].duration0 ) );
printf(",%i", dur( items[i].level1, items[i].duration1 ) );
}
printf("\n");
// turn off visible led
gpio_set_level(LED_BUILTIN, 0);
// free up data space
vRingbufferReturnItem(rb, (void*) items);
receive_decode();
xTaskCreate(rmt_example_nec_tx_task, "rmt_nec_tx_task", 4096, NULL, 10, NULL);
}
}
// delay 100 milliseconds. No need to overheat the processor
vTaskDelay( 100 / portTICK_PERIOD_MS );
}
//vTaskDelete(NULL);
}

Mitsubishi AC is not responding.


Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby Ritesh » Sun Sep 20, 2020 9:30 am

Hello Espressif Team,

Please help sam if anyone has any idea or ported example as per his requirements
Regards,
Ritesh Prajapati

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby Ritesh » Tue Sep 22, 2020 1:22 pm

Hello ESP_Sprite,

Do you have any idea like issue which has been raised by Mr Sam?
Regards,
Ritesh Prajapati

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby ESP_Sprite » Wed Sep 23, 2020 10:08 am

Ritesh wrote:
Tue Sep 22, 2020 1:22 pm
Do you have any idea like issue which has been raised by Mr Sam?
No. An error that effectively says 'this code doesn't work in combination with my airco' is pretty hard to debug without having the airco in question. (Also, please don't ping us. We keep an eye on the forum; we respond if we have something to say.)

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby Ritesh » Wed Sep 23, 2020 11:04 am

ESP_Sprite wrote:
Wed Sep 23, 2020 10:08 am
Ritesh wrote:
Tue Sep 22, 2020 1:22 pm
Do you have any idea like issue which has been raised by Mr Sam?
No. An error that effectively says 'this code doesn't work in combination with my airco' is pretty hard to debug without having the airco in question. (Also, please don't ping us. We keep an eye on the forum; we respond if we have something to say.)
Hello,

Thanks for your kind response.

So, Let us know which details you need regarding Mitsubishi AC. So, Sam will provide all details for same.
Regards,
Ritesh Prajapati

sam_wesleyIcapo
Posts: 4
Joined: Fri Sep 18, 2020 6:00 am

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby sam_wesleyIcapo » Wed Sep 23, 2020 1:48 pm

I have attached the details of Mitsubishi AC below:
Attachments
Modelno.jpg
Modelno.jpg (78.75 KiB) Viewed 8438 times
dimensions.jpg
dimensions.jpg (52.73 KiB) Viewed 8438 times
Capacity.jpg
Capacity.jpg (67.53 KiB) Viewed 8438 times

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby Ritesh » Thu Sep 24, 2020 4:11 am

Hello ESP_Sprite,

As Sam has provided details with specification for Mitsubishi AC. Let us know if you need anything else from our end to move further for same.
Regards,
Ritesh Prajapati

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby ESP_Sprite » Thu Sep 24, 2020 9:41 am

...how do you expect me to debug a communication issue with a random airco if you give me the specs of it? If I tell you my laptop is a Thinkpad T470S, can you tell me why it crashes sometimes?

If any, please start with debugging this issue yourself instead of going 'doesn't work, let's head to the forums'. Can you confirm you get any output at all? Do you have a logic analyzer? Can you check the protocol of an existing remote control and see how it differs from the output values of your code?

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Regarding rmt_tx library to transmit rawData to Mitsubishi AC

Postby Ritesh » Thu Sep 24, 2020 6:00 pm

ESP_Sprite wrote:
Thu Sep 24, 2020 9:41 am
...how do you expect me to debug a communication issue with a random airco if you give me the specs of it? If I tell you my laptop is a Thinkpad T470S, can you tell me why it crashes sometimes?

If any, please start with debugging this issue yourself instead of going 'doesn't work, let's head to the forums'. Can you confirm you get any output at all? Do you have a logic analyzer? Can you check the protocol of an existing remote control and see how it differs from the output values of your code?
Hello ESP_Sprite,

Thanks for your quick and valuable response.

Yes. Sam is trying to debug from their end with his best way.

So He has already checked same AC with other board which is not ESP32 but different one in which he is able to send and receive data without any issue.

So, He is facing issue while using with ESP32 only. That is why he has post request over here and provided details.

Still, Sam will check through logic analyzer and compare pattern with working board. So at least he will get some more idea regarding this issue.
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: No registered users and 313 guests