Okay, what I am trying to do: Recreate (sort of) Pololu's IR beacon (receiver part anyway)
I will be using 4 38kHz IR receivers and using the IR-remote library for multiple receivers.
I want to build a standalone board using an Atmega328p (I have a few laying around) or Attiny4313 (if possible, 328 seems like overkill.
So the principle is I have a beacon that I built using an ATtiny85 and 4 IR leds.
here is the code:
void setup()
{
PORTB = 0;
DDRB = 0b00000010; // set PB1 (= OCR1A) to be an output
}
// Set the frequency that we will get on pin OCR1A but don't turn it on
void setFrequency(uint16_t freq)
{
uint32_t requiredDivisor = (F_CPU / 2) / (uint32_t)freq;
uint16_t prescalerVal = 1;
uint8_t prescalerBits = 1;
while ((requiredDivisor + prescalerVal / 2) / prescalerVal > 256)
{
++prescalerBits;
prescalerVal <<= 1;
}
uint8_t top = ((requiredDivisor + (prescalerVal / 2)) / prescalerVal) - 1;
TCCR1 = (1 << CTC1) | prescalerBits;
GTCCR = 0;
OCR1C = top;
}
// Turn the frequency on
void on()
{
TCNT1 = 0;
TCCR1 |= (1 << COM1A0);
}
// Turn the frequency off and turn off the IR LED.
// We let the counter continue running, we just turn off the OCR1A pin.
void off()
{
TCCR1 &= ~(1 << COM1A0);
}
void loop() {
setFrequency(38000);
for (int i = 0; i < 4; i++) {
on();
delay(1);
off();
delay(1);
}
delay(250);
}
Which outputs dbc8cb72. Great, I have my RX sketch receiving these values and comparing to make sure it is in fact the signal from the beacon, and not stray signals. The PROBLEM is that even with one receiver connected, it sometimes registers the value as coming from the second receiver, even though nothing is connected to that pin.
Should output a picture of an up arrow on the Nokia 5110 if detected from the first IR_recv and arrow down if from IR_recv2.
The final product will have four sensors, but for ease of testing, I am going for two at the moment.
Here is the code:
// LCD5110_Bitmap
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program requires a Nokia 5110 LCD module.
//
// It is assumed that the LCD module is connected to
// the following pins using a levelshifter to get the
// correct voltage to the module.
// SCK - Pin 8
// MOSI - Pin 9
// DC - Pin 10
// RST - Pin 11
// CS - Pin 12
//
#include <LCD5110_Basic.h>
#include <IRremote.h>
int RECV_PIN = 2;
int RECV_PIN2 = 4;
IRrecv irrecv(RECV_PIN);
IRrecv irrecv2(RECV_PIN2);
decode_results results;
decode_results results2;
LCD5110 myGLCD(8, 9, 10, 11, 12);
String resultsStr;
String resultsStr2;
extern uint8_t SmallFont[];
extern uint8_t arrow_right[]; //arrow_right.c
extern uint8_t arrow_up[]; //arrow_up.c
extern uint8_t arrow_left[]; //arrow_left.c
extern uint8_t arrow_down[]; //arrow_down.c
void setup()
{
irrecv.enableIRIn();
irrecv2.enableIRIn();
myGLCD.InitLCD();
}
void displayIR(decode_results *results) {
myGLCD.clrScr();
resultsStr = String(results->value, HEX);
myGLCD.setFont(SmallFont);
myGLCD.print(resultsStr, 0 , 0);
delay(500);
return;
}
void displayIR2(decode_results *results2) {
myGLCD.clrScr();
resultsStr2 = String(results2->value, HEX);
myGLCD.setFont(SmallFont);
myGLCD.print(resultsStr2, 0 , 8);
delay(500);
return;
}
void loop()
{
decode_results results;
decode_results results2;
if (irrecv.decode(&results)) { // Grab an IR code
displayIR(&results);
if (resultsStr == "dbc8cb72") {
myGLCD.clrScr();
myGLCD.drawBitmap(0, 0, arrow_up , 84, 48);
delay(100);
}
else {
myGLCD.clrScr();
myGLCD.print("NOPE", CENTER, 0);
}
irrecv.resume();
}
if (irrecv2.decode(&results2)) { // Grab an IR code
displayIR2(&results2);
if (resultsStr2 == "dbc8cb72") {
myGLCD.clrScr();
myGLCD.drawBitmap(0, 0, arrow_down , 84, 48);
delay(100);
}
else {
myGLCD.clrScr();
myGLCD.print("NOPE", CENTER, 0);
}
irrecv2.resume();
}
/* myGLCD.clrScr();
myGLCD.drawBitmap(0,0, arrow_right, 84, 48);
delay(1000);
myGLCD.clrScr();
myGLCD.drawBitmap(0,0, arrow_left, 84, 48);
delay(1000);*/
}
The short video below shows the one connected sensor triggering both up and down readings
I couldn't figure out how to embed the video, everything I tried only displayed the text link. Sorry for the extra click and the Giant Post. I know you all are busy people just like me. Thanks in advance.