meloncookie / RemotePy

This is an infrared remote control send / receive library by micropython.
MIT License
22 stars 3 forks source link

Unable to send signal #3

Open Vendelator opened 2 years ago

Vendelator commented 2 years ago

I have been at it for days now without success, i think i need some help.

I am using the Raspberry Pi Pico board for this project, the latest firmware.

I am using this module to send the signal: https://www.electrokit.com/uploads/productfile/41015/41015733_-_IR_Transmitter_Module.pdf (and this one to receive: https://www.electrokit.com/uploads/productfile/41015/41015734_-_IR_Receiver_Module.pdf)

The transceiver is 5V, but is supposed to work with 3V. The TX Signal is connected to GPIO 19 and RX Signal to GPIO 16.

When sending a signal through python directly, the receiver reacts to something being sent. Both List and Tuple seems to yield the same results.

When using GUI, i am able to Record, but unable to Send, and i am prompted with an error message saying it's unable to connect to the device. From what i can tell, this error is generated when signalframe.py uses def _send(self): uses commonication.py if not self._communication.is_connect(): if not self._communication.connect(): messagebox.showerror('Error', "Can't connect device.") self._edit_on() return

I am using the standard pid and vid.

I have tried changing idle back and forth in the Micropython UpyIrTx.

The longest signal i have been able to acquire as of now is 211 long. Over several attempts it seems that if properly recorded, the last highest bit is on 210, but most often it barley reaches 158, which i am assuming is the power state bit, If its low, it enters power saving.

My received signals consists of 4 values. Two which happens initially, and two other through out the code. I am assuming the first part is to make the AC-unit know that it is supposed to receive a signal at all, after which the actual command is sent?

0001:   8,896
0002:   4,448
0003:     556
0004:   1,668
0005:     556
0006:   1,668
0007:     556
0008:     556
0009:     556
0010:     556
0011:     556
0012:     556
0013:     556
0014:     556
0015:     556
0016:   1,668
0017:     556
0018:   1,668
0019:     556
0020:   1,668
0021:     556
0022:   1,668
0023:     556
0024:   1,668
0025:     556
0026:     556
0027:     556
0028:   1,668
0029:     556
0030:     556
0031:     556
0032:   1,668
0033:     556
0034:     556
0035:     556
0036:     556
0037:     556
0038:     556
0039:     556
0040:     556
0041:     556
0042:     556
0043:     556
0044:     556
0045:     556
0046:   1,668
0047:     556
0048:   1,668
0049:     556
0050:   1,668
0051:     556
0052:     556
0053:     556
0054:     556
0055:     556
0056:     556
0057:     556
0058:     556
0059:     556
0060:     556
0061:     556
0062:     556
0063:     556
0064:     556
0065:     556
0066:     556
0067:     556
0068:     556
0069:     556
0070:     556
0071:     556
0072:     556
0073:     556
0074:     556
0075:     556
0076:     556
0077:     556
0078:   1,668
0079:     556
0080:     556
0081:     556
0082:   1,668
0083:     556
0084:     556
0085:     556
0086:     556
0087:     556
0088:     556
0089:     556
0090:     556
0091:     556
0092:     556
0093:     556
0094:     556
0095:     556
0096:     556
0097:     556
0098:     556
0099:     556
0100:     556
0101:     556
0102:     556
0103:     556
0104:     556
0105:     556
0106:     556
0107:     556
0108:     556
0109:     556
0110:     556
0111:     556
0112:     556
0113:     556
0114:     556
0115:     556
0116:     556
0117:     556
0118:     556
0119:     556
0120:     556
0121:     556
0122:     556
0123:     556
0124:     556
0125:     556
0126:     556
0127:     556
0128:     556
0129:     556
0130:     556
0131:     556
0132:     556
0133:     556
0134:     556
0135:     556
0136:     556
0137:     556
0138:     556
0139:     556
0140:     556
0141:     556
0142:     556
0143:     556
0144:     556
0145:     556
0146:     556
0147:     556
0148:     556
0149:     556
0150:     556
0151:     556
0152:     556
0153:     556
0154:     556
0155:     556
0156:     556
0157:     556
0158:   1,668
0159:     556
0160:     556
0161:     556
0162:     556
0163:     556
0164:     556
0165:     556
0166:     556
0167:     556
0168:     556
0169:     556
0170:     556
0171:     556
0172:     556
0173:     556
0174:     556
0175:     556
0176:     556
0177:     556
0178:     556
0179:     556
0180:     556
0181:     556
0182:     556
0183:     556
0184:     556
0185:     556
0186:     556
0187:     556
0188:     556
0189:     556
0190:     556
0191:     556
0192:     556
0193:     556
0194:     556
0195:     556
0196:     556
0197:     556
0198:   1,668
0199:     556
0200:     556
0201:     556
0202:   1,668
0203:     556
0204:   1,668
0205:     556
0206:   1,668
0207:     556
0208:     556
0209:     556
0210:   1,668
0211:     556
meloncookie commented 2 years ago

I'm sorry for the late reply.

unable to connect to the device.

Since it was written for M5Stack ATOM (Lite, Matrix), it is necessary to rewrite a part of communication.py. See the readme for details.

--- Modify communication.py ---

class Communication():
     _DEFAULT_VID = 11914 # <-- this
     _DEFAULT_PID = 5     # <-- this

And the micropython program main.py also needs to be rewritten.

--- Modify micropython main.py ---

_GROVE_PIN = {'ATOM':  (32, 26),
              'CORE2': (33, 32),
              'BASIC': (22, 21),
              'GRAY':  (22, 21),
              'FIRE':  (22, 21),
              'GO':    (22, 21),
              'Stick': (33, 32),
              'Else':  (16, 19)}  # Rewrite (RxPin Number, TxPin Number) <-- For your PRi Pico
_DEVICE = 'Else'                  # Rewrite 'Else'  <-- For your PRi Pico

The longest signal

Air conditioner signals tend to be long because they send all state variables, even if the temperature is changed.

My received signals consists of 4 values.

This would be the NEC format series.

Header frame => ON: 16T, OFF: 8T (Top of the signal) Bit data Low => ON: T, OFF: T Bit data High => ON: T, OFF: 3T

T = 562[usec]

after which the actual command is sent?

The header frame is followed by the data.

0001: 8,896 # 0002: 4,448 # HEADER 16T/8T 0003: 556 # 0004: 1,668 # T/3T = 1 0005: 556 # 0006: 1,668 # T/3T = 1 0007: 556 # 0008: 556 # T/T = 0 0009: 556 # 0010: 556 # T/T = 0 ...

Demodulated signal = 1100...

Please refer to here. In the case of air conditioners, the signal length is long, so it is derived from the strict NEC format.

the last highest bit is on 210 ... power state bit ...

I couldn't understand here. power state bit???

I hope it helps you even a little.

Vendelator commented 2 years ago

GUI I need to clarify.

When using GUI, i need to unplug and re-connect the Raspberry Pi Pico for each time i want to press record. Then i can record exactly ONE time. Then i need to re-connect the device. I don't have to close the GUI.

I am not able to send from GUI still, even after updating all referenced files used by main.py

Setting up the board Using GPIO 16 as RX and GPIO 19 as TX works well with your PIO Wave, They are also close to each other on the board and are labled as RX and TX pins. Maybe you can add this to your main.py so the the Raspberry Pi Pico is detected and those pins are used?

I am able to get the IR-led module to work using Pin 40 (VBUS) as power source, drawing current directly from USB. This works for up to around 1.5 meters. Pin 39 (VSYS) does not work.

Python main.py I am able to send commands to my AC-unit now, the issue seems to be that i have misinterpreted real code as jitter.

Example of signal containing Auto Mode, 16 DegC, No sleep, No timer, No fan swing, Not in standby: (8992, 4496, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 1686, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 1686, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 1686, 562) So what i have to do now is to record enough signals to interpret what each section does. Your link has been very helpful for me. (This one --> http://elm-chan.org/docs/ir_format.html)

But at the moment, i am able to Turn AC on at 16 Deg Auto Mode, and 17 Deg Auto Mode with fan swinging. So this is awesome. I feel a lot closer to integrating my AC into my smart home.

The code i use:

from micropython import const
from gc import collect
import json
import utime as time
from machine import Pin
from UpyIrTx import UpyIrTx
from UpyIrRx import UpyIrRx

import commander # My signal creator

rx_pin = Pin(16, Pin.IN)   # Pin16 GPIO16 WORKS
rx = UpyIrRx(rx_pin)

tx_pin = Pin(19, Pin.OUT)  # Pin19 GPIO19 Works
tx = UpyIrTx(0, tx_pin)    # 0ch
...

start = input()
rx.record(3000)
if rx.get_mode() == UpyIrRx.MODE_DONE_OK: # Redundant code, will be removed.
    signal_list = rx.get_calibrate_list()
    # ex) [430, 1290, 430, 430, 430, 860, ...]
else:
    signal_list = (8992, 4496, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 562, 1686, 562, 1686, 562, 1686, 562, 1686, 562, 562, 562, 1686, 562, 562, 562, 1686, 562)
print (signal_list) # redundant code

time.sleep(2)
tx.send(commander.signal_compiler("16", "off", "auto", "on"))
print("Auto 16")
time.sleep(2)
tx.send(commander.signal_compiler("17", "on", "auto", "on"))
print("Auto 17 Swing")

Thank you for your thorough answers.

meloncookie commented 2 years ago

GUI

In the GUI, is there a connector plugging and unplugging every time? In my environment, everything is working fine.(RPi Pico + micropython v1.18 & 1.19) I was able to record signal over and over again. I have uploaded the demo application separately for ESP32 and RP2040.

Sample Code for RP2040 : RX pin = 18, TX pin = 19 (Arbitrary by rewriting the source code)

Pin 39 (VSYS) does not work

This pin cannot be used as a power supply. The correct way is to use Vbus (5V). Or use 3V3 (3.3V).

Vendelator commented 2 years ago

I just wanted to update you that i have working hardware and code now. I am using your Tx library for the Pi Pico and it works very well in Node Red over Mosquitto MQTT.

I will update you later on with working circuits i have tested so that users easier can use your nice project with the Pi Pico.

Best Regards.