Audio playback module on ESP8266 fails to initialise - arduino

I have a ESP8266(ESP-12-E) and a DFPlayer Mini
I am running the sample application :
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(2, 5); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop()
{
static unsigned long timer = millis();
if (millis() - timer > 3000) {
timer = millis();
myDFPlayer.next(); //Play next mp3 every 3 second.
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
I have the following pins setup on the DFPlayer Mini counting down the left of the board 1-8:
1 - +5v
2 - ESP-12-E GPIO 2 - Software serial TX
3 - ESP-12-E GPIO 5 - Software serial RX
4 -
5 -
6 - Speaker +
7 - GND
8 - Speaker -
The Serial monitor shows:
DFRobot DFPlayer Mini Demo Initializing DFPlayer ... (May take 3~5
seconds) Unable to begin:
1.Please recheck the connection!
2.Please insert the SD card!
Soft WDT reset
ctx: cont sp: 3ffefc30 end: 3ffefe10 offset: 01b0
stack>>> 3ffefde0: 3ffeeab0 3ffeea88 3ffeed2c 402020c4 3ffefdf0: 3fffdad0 00000000 3ffeeddc 40202fc4 3ffefe00: feefeffe feefeffe
3ffeedf0 40100710 <<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
The stack trace formatted is:
Decoding 3 results
0x402020c4: setup at /Users/user/Documents/Arduino/dfplayer_simple/dfplayer_simple.ino line 42
0x40202fc4: loop_wrapper at /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/core_esp8266_main.cpp line 57
0x40100710: cont_norm at /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/cont.S line 109
I see no activity on the DFPlayer Mini LED, and am not sure where to go from here.

A tad late, but using myDFPlayer.begin(mySoftwareSerial, false) as mentioned has been our work around on every 'duino i've tried (esp8266, esp32, mega, uno, teensy, etc). Might as well just eliminate that check code entirely, as once you tell it no ack, it will pass the test even if no DFPlayer is connected.

On my NodeMCU ESP-12E, because of the label vs. GPIO aliasing, instead of
SoftwareSerial mySoftwareSerial(5,6); //didn't work
I had to use
SoftwareSerial mySoftwareSerial(D5,D6); //worked great!
Using the Arduino IDE, NodeMCU 1.0 ESP-12E board. Weird how the samples online that I came across didn't show this detail. Here's a link to pinout references and other good info for a variety of esp8266 boards.
https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

Related

DF Player Mini on Arduino Uno Not Playing

I have a problem which is driving me crazy .I want to use dfmini player to play Songs on the arduino and output it on a 8 ohm 0.5W Speaker , and nothing is working .I am using the DFRobotDFPlayerMini Library code as is but nothing is playing at all .Here is a photo of my connections.
Image Here
I apologize if my photo is not clear as i don't have time for software drawing, and i didnt use a breadboard as actually the DF Player is slightly bigger than the holes.
The Arduino Pins Used is 11,10 and 5V and 2 Pins for the GND
Here is the Code of the DFRobot Library used as is .
The Files on the SD Card are in a folder mp3 and written as 0001.mp3 0002.mp3 ..etc
When i Connect and try it out . The Blue Led on MP3 Player doesn't light up , and on the Serial Monitor Baud 115200 :
DFRobot DFPlayer Mini
DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
DFPlayer Mini online.
and on Serial Monitor Baud 9600:
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ܙf⸮⸮⸮⸮⸮⸮⸮⸮
Would be very thankful if anyone can solve this problem.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial, false)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop()
{
static unsigned long timer = millis();
if (millis() - timer > 3000) {
timer = millis();
myDFPlayer.next(); //Play next mp3 every 3 second.
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerUSBInserted:
Serial.println("USB Inserted!");
break;
case DFPlayerUSBRemoved:
Serial.println("USB Removed!");
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
Try changing:
if (!myDFPlayer.begin(mySoftwareSerial, false))
to:
if (!myDFPlayer.begin(mySoftwareSerial, true, false))
The problem as it appeared was in the Arduino Cable , Make Sure that the cable itself is working properly

How to switch between bluetooth and wifi in esp32

I am doing an autonomous car project, I need manual control as well as an autonomous function, so the manual control is done through wif using "gesture control" and for the autonomous control I want to send the location data via Bluetooth, I will be choosing between both, using a toggle switch connected to ground and one of the pins. I went through the inbuilt wifi Bluetooth switch program but I have no idea how to modify it. I am still okay if I can send data through the HTTP request but, then I have to connect it to a network right? But again I don't have any idea, how to write the code to switch between the two networks.I am using an ESP32 devkit
This is the inbuilt example code for Bluetooth switch
#include "WiFi.h"
#define STA_SSID "your-ssid"
#define STA_PASS "your-pass"
#define AP_SSID "esp32"
enum { STEP_BTON, STEP_BTOFF, STEP_STA, STEP_AP, STEP_AP_STA, STEP_OFF, STEP_BT_STA, STEP_END };
void onButton(){
static uint32_t step = STEP_BTON;
switch(step){
case STEP_BTON://BT Only
Serial.println("** Starting BT");
btStart();
break;
case STEP_BTOFF://All Off
Serial.println("** Stopping BT");
btStop();
break;
case STEP_STA://STA Only
Serial.println("** Starting STA");
WiFi.begin(STA_SSID, STA_PASS);
break;
case STEP_AP://AP Only
Serial.println("** Stopping STA");
WiFi.mode(WIFI_AP);
Serial.println("** Starting AP");
WiFi.softAP(AP_SSID);
break;
case STEP_AP_STA://AP+STA
Serial.println("** Starting STA");
WiFi.begin(STA_SSID, STA_PASS);
break;
case STEP_OFF://All Off
Serial.println("** Stopping WiFi");
WiFi.mode(WIFI_OFF);
break;
case STEP_BT_STA://BT+STA
Serial.println("** Starting STA+BT");
WiFi.begin(STA_SSID, STA_PASS);
btStart();
break;
case STEP_END://All Off
Serial.println("** Stopping WiFi+BT");
WiFi.mode(WIFI_OFF);
btStop();
break;
default:
break;
}
if(step == STEP_END){
step = STEP_BTON;
} else {
step++;
}
//little debounce
delay(100);
}
void WiFiEvent(WiFiEvent_t event){
switch(event) {
case SYSTEM_EVENT_AP_START:
Serial.println("AP Started");
WiFi.softAPsetHostname(AP_SSID);
break;
case SYSTEM_EVENT_AP_STOP:
Serial.println("AP Stopped");
break;
case SYSTEM_EVENT_STA_START:
Serial.println("STA Started");
WiFi.setHostname(AP_SSID);
break;
case SYSTEM_EVENT_STA_CONNECTED:
Serial.println("STA Connected");
WiFi.enableIpV6();
break;
case SYSTEM_EVENT_AP_STA_GOT_IP6:
Serial.print("STA IPv6: ");
Serial.println(WiFi.localIPv6());
break;
case SYSTEM_EVENT_STA_GOT_IP:
Serial.print("STA IPv4: ");
Serial.println(WiFi.localIP());
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Serial.println("STA Disconnected");
break;
case SYSTEM_EVENT_STA_STOP:
Serial.println("STA Stopped");
break;
default:
break;
}
}
void setup() {
Serial.begin(115200);
pinMode(0, INPUT_PULLUP);
WiFi.onEvent(WiFiEvent);
Serial.print("ESP32 SDK: ");
Serial.println(ESP.getSdkVersion());
Serial.println("Press the button to select the next mode");
}
void loop() {
static uint8_t lastPinState = 1;
uint8_t pinState = digitalRead(0);
if(!pinState && lastPinState){
onButton();
}
lastPinState = pinState;
}
Below is part of the main code i use, i want to modify it so i can either switch between bluetooth and esp now or between espnow and http
*/
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <TinyGPS++.h> // Tiny GPS Plus Library
#define CHANNEL 4
uint8_t mac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x33};
struct __attribute__((packed)) DataStruct {
//char text[32];
int x;
int y;
unsigned long time;
};
DataStruct myData;
//*****************************************************************************************************
// GPS Locations
unsigned long Distance_To_Home; // variable for storing the distance to destination
int ac =0; // GPS array counter
int wpCount = 0; // GPS waypoint counter
double Home_LATarray[50]; // variable for storing the destination Latitude - Only Programmed for 5 waypoint
double Home_LONarray[50]; // variable for storing the destination Longitude - up to 50 waypoints
int increment = 0;
#define autopilot 13
void gesturecontroll();
void getGPS();
void getCompass();
void setWaypoint();
void move();
int blueToothVal;
void setup()
{ Serial.begin(9600); // Serial 0 is for communication with the computer
S2.begin(9600); // Serial 2 is for GPS communication at 9600 baud - DO NOT MODIFY - Ublox Neo 6m
Serial.println("ESPNow/Basic/Slave Example");
//Set device in AP mode to begin with
WiFi.mode(WIFI_AP);
// configure device AP mode
// This is the mac address of the Slave in AP Mode
esp_wifi_set_mac(ESP_IF_WIFI_STA, &mac[0]);
Serial.print("AP MAC: "); Serial.println(WiFi.softAPmacAddress());
// Init ESPNow with a fallback logic
if (esp_now_init()!=0) {
Serial.println("*** ESP_Now init failed");
while(true) {};
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info.
esp_now_register_recv_cb(OnDataRecv);
Serial.print("Aheloiioi");
// Extras////////////////////////////////////////////////////////////////////////////////////
pinMode(autopilot, INPUT);
}
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
memcpy(&myData, data, sizeof(myData));
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
Serial.print("Last Packet Recv from: "); Serial.println(macStr);
Serial.print("Last Packet Recv Data: ");
Serial.println(myData.x);
Serial.println(myData.y);
Serial.println("");
Serial.println();
//move();
Serial.println();
}
//********************************************************************************************************
// Main Loop
void loop()
{ if (autopilot == HIGH)
{
move(); // going for manual control
}
else
{
getGPS(); // Update the GPS location
getCompass(); // Update the CompaSerial Heading
Ping(); // Use at your own discretion, this is not fully tested
}
}
I could have tried if all these initial setups came under an "if statement" in the void loop, but these initial setups come in the void setup,so i have no idea on how to proced
I think this example need hardware also like toggle switch between GPIO 0 & ground on top of the code these comments are there.
//Sketch shows how to switch between Wi-Fi and Bluetooth or use both
// Button is attached between GPIO 0 and GND and modes are switched with each press
this example code as wifi.h library included but "BluetoothSerial.h" library is not included I don't it works properly in real time without this "BluetoothSerial.h" library
About terminology in ESP32 Wi-Fi go through it:- https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html
I think first prepare hardware as given in example then start coding.

External digital interrupt and dht11

I have an Arduino Pro Mini 5v, 16 mhz and it is connected to a digital switch on pin 2. This switch is used to wake the Arduino from sleep using a external digital interrupt. I also have a DHT11 temperature sensor connected to pin 9. What I want to achieve is the when the Arduino is awake for 5 seconds and also when the switch on pin 2 is HIGH, I want to read the temperature sensor and return the temperature. I am using the DHT11 library by Tillart and when I do this, it returns a TIME_OUT error. The only possible explanation I have for this is that somehow the voltage is changed when both the DHT11 and the switch on pin 2 is being read together? Any pointers to a solution will be greatly appreciated. Thank you.
Edit 1: Added code
#include <LowPower.h>
#include <dht.h>
int pin2 = 2;
dht DHT;
#define DHT11_PIN 9
void pin2interrupt(void)
{
// Function called when awoken from sleep
// Detach interrupt to stop it from continuosly firing when in normal mode
}
void enterSleep(void)
{
attachInterrupt(0, pin2interrupt, HIGH);
Serial.println("Sleeping");
delay(100);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
Serial.println("Awake!");
}
void setup()
{
Serial.begin(115200);
pinMode(pin2, INPUT);
pinMode(DHT11_PIN, INPUT);
}
int seconds = 0;
void loop()
{
delay(1000);
seconds++;
Serial.println("Awake in the loop!");
Serial.println(seconds);
if (digitalRead(pin2) == LOW && seconds == 5)
{
seconds = 0;
Serial.println("No child detected, so going to sleep!");
delay(200);
enterSleep();
}
else if (seconds == 5)
{
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.println(DHT.temperature, 1);
delay(2000);
seconds = 0;
}
}
Edit 2: I also forgot to to mention that I am using the LowPower library by RocketScream to put the Arduino to sleep. The library can be found here: https://github.com/rocketscream/Low-Power
As discussed in the issues section on the official Github page of the DHT11 library by Rob Tillart, the problem is caused because some DHT11 sensors take longer to transfer data back to the board then the 50ms or so specified on the datasheet. Therefore, if you are encountering this problem try increasing the DHTLIB_TIMEOUT on the dht header file by reducing the the value dividing the F_CPU value to around 400 and try again. This allows the board to wait longer than 50ms for the board to receive data back from the sensor. If this fix doesn't work, you might want to try measuring the response time using an oscilloscope as it seems some DHT11 are built differently.

How can I get rid of error: 'SerialUSB' was not declared in this scope in my Arduino Sketch?

The code is below, slightly modified from a tutorial. I am working on a Teensy3.1. I added #include <SoftwareSerial.h> but it did not help. I also tried SerialUSB.begin(9600); instead of WiredSerial.begin(9600); //use native port on Due
#include <SoftwareSerial.h>
//minimal sketch for connection to ADS129n family. Load this script and open Tools/SerialMonitor.
//You should see text like this
// Device Type (ID Control Register): 62 Channels: 8
//If you see "Channels: 0" then check your wiring
#include "ads1298.h"
#include "adsCMD.h"
#include <Arduino.h>
#include <SPI.h> // include the SPI library:
int gMaxChan = 0; //maximum number of channels supported by ads129n = 4,6,8
int gIDval = 0; //Device ID : lower 5 bits of ID Control Register
int activeSerialPort = 0; //data will be sent to serial port that last sent commands. E.G. bluetooth or USB port
const int kPIN_LED = 13;//pin with in-built light - typically 13, 11 for Teensy 2.0.
#if defined(__SAM3X8E__)
#define isDUE //Detect Arduino Due
#define WiredSerial SerialUSB //Use Due's Native port
#else
#define WiredSerial Serial
#endif
void setup(){
using namespace ADS1298;
//prepare pins to be outputs or inputs
//pinMode(PIN_SCLK, OUTPUT); //optional - SPI library will do this for us
//pinMode(PIN_DIN, OUTPUT); //optional - SPI library will do this for us
//pinMode(PIN_DOUT, INPUT); //optional - SPI library will do this for us
pinMode(IPIN_CS, OUTPUT);
pinMode(PIN_START, OUTPUT);
pinMode(IPIN_DRDY, INPUT);
//pinMode(PIN_CLKSEL, OUTPUT);//*optional
//pinMode(IPIN_RESET, OUTPUT);//*optional
//pinMode(IPIN_PWDN, OUTPUT);//*optional
//start small peripheral interface
SPI.begin();
SPI.setBitOrder(MSBFIRST);
#ifndef isDUE
SPI.setClockDivider(SPI_CLOCK_DIV4); //http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions
#endif
SPI.setDataMode(SPI_MODE1);
//Start ADS1298
delay(500); //wait for the ads129n to be ready - it can take a while to charge caps
adc_send_command(SDATAC); // Send SDATAC Command (Stop Read Data Continuously mode)
delay(10);
// Determine model number and number of channels available
gIDval = adc_rreg(ID); //lower 5 bits of register 0 reveal chip type
switch (gIDval & B00011111 ) { //least significant bits reports channels
case B10000: //16
gMaxChan = 4; //ads1294
break;
case B10001: //17
gMaxChan = 6; //ads1296
break;
case B10010: //18
gMaxChan = 8; //ads1298
break;
case B11110: //30
gMaxChan = 8; //ads1299
break;
default:
gMaxChan = 0;
}
//start serial port
SerialUSB.begin(9600); //use native port on Due
//WiredSerial.begin(9600); //use native port on Due
while (WiredSerial.read() >= 0) {} //http://forum.arduino.cc/index.php?topic=134847.0
//while (!WiredSerial) ; //required by Leonardo http://arduino.cc/en/Serial/IfSerial (ads129n requires 3.3v signals, Leonardo is 5v)
delay(200); // Catch Due reset problem
pinMode(kPIN_LED, OUTPUT);
}
void loop()
{
WiredSerial.print("Device Type (ID Control Register): "); SerialUSB.print(gIDval); SerialUSB.print(" Channels: "); SerialUSB.println(gMaxChan);
digitalWrite(kPIN_LED, HIGH); // turn the LED on (HIGH is the voltage level)
if (gMaxChan > 0)
delay(500); //long pause if OK
else
delay(50); //rapid blink if error
digitalWrite(kPIN_LED, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
Try using Serial instead of SerialUSB, I've tried it while using Arduino UNO.

arduino program runs only at start up

My arduino program runs only when on start up or when i press the reset button, i dont know the problem as i am a new bee into this. Please need help.
i have some constants here for the remote control, and i am just trying to replicate what i am sending through the arduino ir led, every thing works fine except that the program runs only once.
#include <IRremote.h> // use the library
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
#define PanasonicPower 0x100BCBD // Panasonic Power button
#define PanasonicZero 0x1009899 // Panasonic button
#define PanasonicOne 0x1000809 // Panasonic button
#define PanasonicTwo 0x1008889 // Panasonic button
#define PanasonicThree 0x1004849 // Panasonic button
#define PanasonicFour 0x100C8C9 // Panasonic button
#define PanasonicFive 0x1002829 // Panasonic button
#define PanasonicSix 0x100A8A9 // Panasonic button
#define PanasonicSeven 0x1006869 // Panasonic button
#define PanasonicEight 0x100E8E9 // Panasonic button
#define PanasonicNine 0x1001819 // Panasonic button
#define PMute 0x1004C4D
#define PCPlus 0x1002C2D
#define PCMinus 0x100ACAD
#define PVMinus 0x1008485
#define PVPlus 0x1000405
#define PRTune 0x100ECED
#define JVCPower 0xC5E8
int receiverpin = 15; // pin 1 of IR receiver to Arduino digital pin 15
IRsend irsend;
IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // start the IR receiver
// pinMode(7, OUTPUT);
for (int z = 11 ; z < 14 ; z++) // set up digital pins
{
pinMode(z, OUTPUT);
}
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
for (int z = 0 ; z < 2 ; z++) // ignore the repeated codes
{
irrecv.resume(); // receive the next value
}
}
}
void translateIR()
// takes action based on IR code received
// uses Sony IR codes
{
switch(results.value)
{
case PanasonicFour: pinOnTriple(1, 0, 0);
irsend.sendPanasonic(PanasonicAddress,PanasonicFour); // This should turn your TV on and off
break; // 2
case PanasonicTwo: pinOnTriple(0, 1, 0);
irsend.sendPanasonic(PanasonicAddress,PanasonicTwo);
break; // 3
case PanasonicFive: pinOnTriple(HIGH, LOW, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicFive);
break; // 5
case PanasonicSix: pinOnTriple(HIGH, HIGH, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicSix);
break; // 6
case PanasonicSeven: pinOnTriple(HIGH, HIGH, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicSeven);
break; // 7
case PanasonicZero: pinOnTriple(LOW, LOW, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicZero);
break; // 8
case PanasonicOne: pinOnTriple(LOW, LOW, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicOne);
break; // 9
case PanasonicThree: pinOnTriple(LOW, HIGH, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicThree);
break; // 10
case 0x100BCBD: pinOnTriple(LOW, LOW, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off
irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat
delay(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information
irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat
delay(50);
break;
case 0x1004C4D:
irsend.sendPanasonic(PanasonicAddress,PMute);
break; // 11
case 0x1002C2D:
irsend.sendPanasonic(PanasonicAddress,PCPlus);
break; // 11
case 0x100ACAD:
irsend.sendPanasonic(PanasonicAddress,PCMinus);
break; // 11
case 0x1008485:
irsend.sendPanasonic(PanasonicAddress,PVMinus);
break; // 11
case 0x1000405:
irsend.sendPanasonic(PanasonicAddress,PVPlus);
break; // 11
case 0x100ECED:
irsend.sendPanasonic(PanasonicAddress,PRTune);
break; // 11
}
}
void pinOnTriple(int pin, int pino, int pini) // turns on digital pins for 1 second
{
digitalWrite(11, pin);
digitalWrite(12, pino);
digitalWrite(13, pini);
delay(1000);
digitalWrite(11, 0);
digitalWrite(12, 0);
digitalWrite(13, 0);
}
You should just check for receiving the repeat codes (0xFFFFFF) and just ignore this code. And just issue the resume command just once. You may be accidently skipping the valid codes.
Also, you need to issue a resume after transmitting IR (as tx disables rx).
This last one is probably the issue for you.
Hope it helps
may be worth putting in a delay before re-tx as the tx may overlap the repeat codes
For anyone interested in IR protocols - we have just launched a project for AnalysIR - IR Decoder & Analyzer GUI (Arduino & Raspberry Pi). Currently we support 17 IR protocols and are looking for more to add as part of the campaign. Suggestions Welcome!
If the project is successful, we hope to add support for Raspberry Pi !
You can find out more and support the Project by visiting http://igg.me/at/AnalysIR/x/3752156 or Screenshot via www.AnalysIR.com

Resources