PDA

View Full Version : VS1838B remote



Michael
- 23rd March 2020, 17:13
These popular 3 pin infrared receivers --

https://www.amazon.com/gp/product/B07PXV5DDF/ref=ox_sc_act_title_1?smid=A5I5XFYWMWKVM&psc=1

are used a lot with the arduino stuff but has anyone run across any picbasic code using them? don't want to start from scratch based on my previous attempts to use picbasic for a remote. (a pain if I remember right). THANKS.

just need it to do a simple on/off which is easy if you just detect basic IR but don't want the possibility of ambient light triggering it so just one basic on/off data stream would work.

Michael
- 23rd March 2020, 23:00
I'm thinking the way to do it is use COUNT and just look for X amount of pulses from the 38khz ired xmtr. If > X then high a pin.
Should work I hope. ?

Michael
- 24th March 2020, 16:27
Bummer. Never used COUNT before, maybe I'm missing something?

CT VAR WORD

COUNT portb.5, 1000, CT
IF CT > 10 then
HIGH porta.7
CT = 0
ENDIF

Getting nothing. Using 16f628a and 4mhz.

I have no doubt there are more than 10 pulses in a second with the ired data out.

Michael
- 24th March 2020, 16:35
Presto -- thought I had the count set at 10 (was 20) -- working great now.
Like the way I have conversations with myself on the forum? :)

Kind of a cool way to use these ired units for a simple foolproof switch actually.

andybarrett1
- 27th March 2020, 09:51
Hi ...

I am using same code ish


count ir,500,realtrig ' Looks for real trigger
if realtrig >15 then 'if real ir then turn light on
gosub Seconds 'then on 88 Seconds
endif
return



Works fine for me also..... But I I am getting false triggers due to mains spikes (My circuit is on a 12v Battery then LDO down to 5v....Was wondering what your circuit looked like ... If I was missing anything maybe ...



Andy

Acetronics2
- 28th March 2020, 09:27
Hi,

I think the best way would be to use the PULSIN command ( or use the PIC Capture HW function ...) ... just to be sure no false signal incoming : you can have one or two valid pulses windows ( signal 0 and 1 ... i.e. )
count counts ... everything !!!

may be you also could have a look to RC5 like IR codes ...

Alain

gebillpap
- 28th March 2020, 16:11
Once upon a time , there was a brilliant and very helpfull gentleman named Bruce Reynold.
He posted some Infra Red routines for PIC's in PICBASIC at his site Rentron.com which now is lost.
The general idea was to create a routine ,at the encoder ,which lasted in total 26μs and a dutycycle of 25% toggling a port bit on and off thus having a frequency of 38Khz.
I kept a copy and maybe you can get an idea

PROCESSOR 12c508
#include "p12c508.inc"
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
#DEFINE PORT B'11111101'
MOVF OSCCAL
MOVLW PORT
TRIS GPIO

BEGIN
BCF GPIO, 1 ;1uS
NOP ;2uS each nop is 1uS long
NOP ;3uS
NOP ;4uS
NOP ;5uS
NOP ;6uS
NOP ;7uS
NOP ;8uS
NOP ;9uS
NOP ;10uS
NOP ;11uS
NOP ;12uS
NOP ;13uS
NOP ;14uS
NOP ;15uS
NOP ;16uS
NOP ;17uS
NOP ;18uS
NOP ;19uS low on gpio.0
BSF GPIO, 1 ;1uS Begin HIGH duty cycle
NOP ;2uS
NOP ;3uS
NOP ;4uS
NOP ;5uS
GOTO BEGIN ;2uS (26uS total for 38KHz)
END

I remember that he also had a working example with a pair of pic16f628 for remote control.
Maybe somebody can help further.
Regards

Michael
- 28th March 2020, 20:51
I remember the Rentron stuff -- excellent. Thanks for that code, I'll look into it and play with pulsin. It should be more accurate sounds like.

It's working 98% of the time but alas, that isn't good enough. The goal is a foolproof on/off switch just sensing Ired.
Noise is the problem with those receivers.

Michael
- 29th March 2020, 13:47
Never used pulsin. So if I knew the pulse width of the 38khz signal, I can compare it to a result pulsin gives? I just read something where it says it measures just one pulse, either low or high state and then goes to next instruction? Why a word variable if it just measures once?

I get frustrated with some of the PBP commands. The manual is too vague. Wish for every command they could have done another page just with code examples and an explanation of what's going on. (just me venting).

Michael
- 29th March 2020, 15:40
I found that Rentron code. Wow. It's all there and well commented -- I'll try it out. His comments really spell it out and teach.

Michael
- 29th March 2020, 18:07
Pulsin works great. Heck, I just used the first part of that rentron code and did this with it --
I get a perfect momentary on/off with a bit of needed pause.


Main:
PULSIN PORTB.0,0,Leader ' leader pulse is ~9mS low-going
IF Leader < 850 THEN
LOW PORTB.2
GOTO Main
ENDIF

IF LEADER > 850 THEN
HIGH PORTB.2
PAUSE 300
ENDIF

LEADER = 0
PAUSE 100

GOTO MAIN

andybarrett1
- 1st April 2020, 15:46
Pulsin works great. Heck, I just used the first part of that rentron code and did this with it --
I get a perfect momentary on/off with a bit of needed pause.


Main:
PULSIN PORTB.0,0,Leader ' leader pulse is ~9mS low-going
IF Leader < 850 THEN
LOW PORTB.2
GOTO Main
ENDIF

IF LEADER > 850 THEN
HIGH PORTB.2
PAUSE 300
ENDIF

LEADER = 0
PAUSE 100

GOTO MAIN

Just a question ......Why:-


GOTO Main
ENDIF


I would assume the other way round .....Genuine question. I can never understand software fully :-)

Andy

mpgmike
- 1st April 2020, 16:24
I think it's a method of skipping other IF/THEN options.

It could also be structured with...

IF This THEN
do something
ELSEIF That THEN
do something else
ELSE None of the above
Don't do anything
ENDIF

Only 1 option will be selected, forcing a break from the test once a match is found.

andybarrett1
- 1st April 2020, 16:48
I think it's a method of skipping other IF/THEN options.

It could also be structured with...

IF This THEN
do something
ELSEIF That THEN
do something else
ELSE None of the above
Don't do anything
ENDIF

Only 1 option will be selected, forcing a break from the test once a match is found.

Got it

Thank you

Michael
- 3rd April 2020, 14:22
it's working fine but I added leader = 0 to clear it out (duh)
should have thought of that.
I need to put the breadboard in the sunshine and see if it stays stable.
if not, I'll just add his decoding the bytes data

kind of nice using any button on the remote

Main:
PULSIN PORTB.0,0,LEADER ' leader pulse is ~9mS low-going
IF Leader < 850 THEN
LOW PORTB.2
LEADER = 0
GOTO Main
ENDIF

and yes, could have used else but so simple just wanted to see if functions.

Ioannis
- 4th April 2020, 10:54
Another one for F675 chip



'* Author : Craig S Gardner, Modified by Jonathan Peakall to *
'* : allow baud rate selection. *
CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF -- Port pins all digital
TRISIO = %010000 ' All I/O but GPIO3 = outputs
GPIO = %000000 ' All 0 on boot


sBaud var byte
IRpulse_length var word(13)
xx var Byte
Command Var Byte
Device Var Byte
input gpio.3
'clear
pause 500
sbaud = 2
if gpio.3 = 1 then
sBaud = 2
endif

if gpio.3 = 0 then
sBaud = 0
endif

Getstartbits:
PuLSIN GPIO.1,0,IRpulse_length(0)
if IRpulse_length(0) < 200 then
goto getstartbits
Endif

for xx=1 to 12
pulsin GPIO.1,0,IRpulse_length(xx)
next xx



displaybits:
if IRpulse_length(1) < 100 then
Command.bit0 = 0
Else
Command.bit0 = 1
endif
if IRpulse_length(2) < 100 then
Command.bit1 = 0
Else
Command.bit1 = 1
endif
if IRpulse_length(3) < 100 then
Command.bit2 = 0
Else
Command.bit2 = 1
endif
if IRpulse_length(4) < 100 then
Command.bit3 = 0
Else
Command.bit3 = 1
endif
if IRpulse_length(5) < 100 then
Command.bit4 = 0
Else
Command.bit4 = 1
endif
if IRpulse_length(6) < 100 then
Command.bit5 = 0
Else
Command.bit5 = 1
endif
if IRpulse_length(7) < 100 then
Command.bit6 = 0
Else
Command.bit6 = 1
endif
Command.bit7 = 0
Command = Command + 1
If Command = 10 then
Command = 0
Endif



if IRpulse_length(8) < 100 then
Device.bit0 = 0
Else
Device.bit0 = 1
endif
if IRpulse_length(9) < 100 then
Device.bit1 = 0
Else
Device.bit1 = 1
endif
if IRpulse_length(10) < 100 then
Device.bit2 = 0
Else
Device.bit2 = 1
endif
if IRpulse_length(11) < 100 then
Device.bit3 = 0
Else
Device.bit3 = 1
endif
'Device.bit1 = 0



SEROUT GPIO.0,sbaud,[Device,Command]
pause 100
goto Getstartbits


Ioannis

Ioannis
- 4th April 2020, 12:40
And another one, very educative.

8807

Ioannis

Michael
- 4th April 2020, 13:57
Thanks Ioannis. That pdf will be my reading later. I may want to do more sophisticated RC stuff also.
This simple on/off is working great -- only sees NEC remotes. Tried others and no go which is good.
I suppose you could even set up another counter to get simple on/offs on other pins, press twice within 10 seconds and so on.
But not going there.

Ioannis
- 4th April 2020, 18:08
If you are able to decode the transmitted button press, then you can do anything you want. The pdf is close to what you need.

Ioannis