|
Edited by nopnop2002 at 2016-8-3 21:19
I could control using external IR receiver by combining with ATtiny.
My RPI-ONE (This have No IR) can control using a remote control.
1. A sketch is written in ATtiny85.
The sketch is as follows.
ATtiny85 sends a received infrared code using UART.
This can distinguish only the NEC format.
Original is here.
http://www.technoblogy.com/show?V6F
- /* ATtiny85 IR Remote Control Receiver
- David Johnson-Davies - www.technoblogy.com - 3rd April 2015
- ATtiny85 @ 1 MHz (internal oscillator; BOD disabled)
-
- CC BY 4.0
- Licensed under a Creative Commons Attribution 4.0 International license:
- http://creativecommons.org/licenses/by/4.0/
- http://www.technoblogy.com/show?V6F
-
- */
- #include <SoftwareSerial.h>
- #define rxPin 0 // PB0
- #define txPin 1 // PB1
- SoftwareSerial mySerial(rxPin, txPin); // RX, TX
- volatile int NextBit;
- volatile unsigned long RecdData;
- // Demo routine
- void ReceivedCode(boolean Repeat) {
- // char buff[64];
- // sprintf(buff,"%d,%x",Repeat,RecdData);
- // mySerial.println(buff);
- mySerial.print(Repeat);
- mySerial.print(",");
- mySerial.println(RecdData,HEX);
- }
- // Interrupt service routine - called on every falling edge of PB2
- ISR(INT0_vect) {
- int Time = TCNT0;
- int Overflow = TIFR & 1<<TOV0;
- // Keep looking for AGC pulse and gap
- if (NextBit == 32) {
- if ((Time >= 194) && (Time <= 228) && (Overflow == 0)) {
- RecdData = 0; NextBit = 0;
- } else if ((Time >= 159) && (Time <= 193) && (Overflow == 0)) ReceivedCode(1);
- // Data bit
- } else {
- if ((Time > 44) || (Overflow != 0)) NextBit = 32; // Invalid - restart
- else {
- if (Time > 26) RecdData = RecdData | ((unsigned long) 1<<NextBit);
- if (NextBit == 31) ReceivedCode(0);
- NextBit++;
- }
- }
- TCNT0 = 0; // Clear counter
- TIFR = TIFR | 1<<TOV0; // Clear overflow
- GIFR = GIFR | 1<<INTF0; // Clear INT0 flag
- }
- // Setup **********************************************
- void setup() {
- // Set up Timer/Counter0 (assumes 1MHz clock)
- TCCR0A = 0; // No compare matches
- TCCR0B = 3<<CS00; // Prescaler /64
- // Set up INT0 interrupt on PB2
- MCUCR = MCUCR | 2<<ISC00; // Interrupt on falling edge
- GIMSK = GIMSK | 1<<INT0; // Enable INT0
- NextBit = 32; // Wait for AGC start pulse
- mySerial.begin(4800);
- mySerial.println("IR demo start");
- }
- void loop()
Copy code
2.Wiring ATtiny85 and RPI-ONE.
A wiring diagram is this.
It don't have a part image of OPI, so I substituted a part image of RPI.
If someone have a part image of OPI, please share.
http://nopnop2002.webcrow.jp/OrangePiONE/OrangePiOne-2.html
**ATtiny operate 5V.
**So you need level shift.
**When ATtiny operate 3.3V,It can't receive IR.
3.Download sirw and sirexec.
Source code of sirw is this.
http://nopnop2002.webcrow.jp/OrangePiONE/ir/sirw.c
Source code of sirexec is this.
http://nopnop2002.webcrow.jp/OrangePiONE/ir/sirexec.c
$cc -o sirw sirw.c -lwiringPi
$cc -o sirexec sirexec.c -lwiringPi
4. Execute sirw.
$sudo ./sirw
When you push any remote,sirw indicates a remote control code.
When you'd like to use ttyS2 or ttyS3:
$sudo ./sirw /dev/ttyS2
$sudo ./sirw /dev/ttyS3
5. You take notes of an IR code.
The first 1 character is indicator whether repeat or not.
1,E619FF00:This is repeat code
0,E619FF00:This is not repeat code
E619FF00 is IR code.
6.Stop sirw.
Create config file in $HOME.
Everything is good for the file name.
Example:
#ok
EA15FF00,uname -a
#menu
BC43FF00,ls /boot
When receive EA15FF00,[uname -a] is executed.
When receive EA15FF00,[ls /boot] is executed.
7. Execute sirexec.
$sudo ./sirexec /dev/ttyS1 $HOME/config debug
When you'd like to use ttyS2 or ttyS3:
$sudo ./sirexec /dev/ttyS2 $HOME/config debug
$sudo ./sirexec /dev/ttyS3 $HOME/config debug
When you push remote, sirexec execute a command.
**Last argument "debug" is for test.
**When including in your /etc/rc.local, please remove the last argument "debug".
|
|