Buenas a todos. Soy nuevo y espero redactar bien el post y expresar bien mi problema.
Mi problema es que no consigo que funcione el LCD.
Os explico, tengo un par de Arduinos UNO conectados a unos módulos NRF24L01 a modo de Walkie-talkies y funcionan correctamente, aquí os pongo un esquema:
Este es el código que utilizo:
#include <RF24.h>
#include <SPI.h>
#include <RF24Audio.h>
#include "printf.h"
#include "userConfig.h"
RF24 radio(7,8);
RF24Audio rfAudio(radio,0);
int talkButton = 3;
void setup()
{
Serial.begin(115200);
printf_begin();
radio.begin();
radio.printDetails();
rfAudio.begin();
pinMode(talkButton, INPUT);
attachInterrupt(digitalPinToInterrupt(talkButton), talk, CHANGE); //Interrupcción en modo de cambio (CHANGE)
rfAudio.receive();
}
void talk()
{
if (digitalRead(talkButton)) rfAudio.transmit();
else rfAudio.receive();
}
void loop() {
}
(Decir que el "userConfig.h" lo añado como fichero aparte para modificar algunas características del módulo NRF24L01):
/***********************************************
//******* MANDATORY User Variables **************/
// Maximum Range: Sample rate 16000, RF_SPEED RF24_250KBPS
// Maximum Quality: Sample rate 44000, RF_SPEED RF24_2MBPS
#define SAMPLE_RATE 24000 // The sample rate to use for transferring audio samples Note: 44khz+ sample rate requires 8-bits per sample
#define RF_SPEED RF24_1MBPS // RF24_250KBPS will do 13-20khz+ sample rate, RF24_1MBPS up to 24-44khz+, RF24_2MBPS for higher. These are not limits, just a guide.
#define ANALOG_PIN A0 // The pin that analog readings will be taken from (microphone pin)
/************ OverRides *************************/
//10-bit audio requires more bandwidth. A 20khz sample rate will need 25KB/S transfer rate, which is about max for 250kbps data rate.
//With a 32khz sample rate, the volume can be set to -1 to shift the sample down to 9-bit, which is the highest the timers can handle at 32khz
//#define tenBit // Enable 10-bit samples Note: 44khz+ sample rate requires 8-bits per sample
//#define speakerPin 9 // If using a non-standard board, override the timer1 pins
//#define speakerPin 10
#define ENABLE_LED // Indicator pin. Using pin 6 on Uno enables audio visualization. Pin 13 on Mega 2560 (TIMER0 COMPA) The pin# cannot be changed.
/***************** Optional/Advanced User Variables ******/
//#define MANUAL_BUTTON_HANDLING // Disables button handling via timer0. Allow users to customize button handling
//#define TX_PIN A1 // Button pin to trigger recording & transmission
#define VOL_UP_PIN A2 // Pin for external volume control
#define VOL_DN_PIN A3 // Pin for external volume control
//#define REMOTE_TX_PIN A4 // Pin for externally triggering remote recording
//#define REMOTE_RX_PIN 4 // Pin for externally stopping remote recording (needs timeout enabled)
#define buffSize 32 // The size of the memory buffer to use. Not really configurable.
//#define speakerTX // Whether to output to speaker while transmitting
//#define oversampling // Oversampling is recommended for low sample rates only. This only affects playback.
//#define RX_ONLY
//#define TX_ONLY // Not functional yet
/********* Automated pin selections, override by defining above ************/
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || (__AVR_ATmega32U4__) || (__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || (__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
#define rampMega
#if !defined (speakerPin) //Speaker pin selection for mega etc
#define speakerPin 11 //The pins to output audio on. (11,12 on Mega 2560)
#endif
#if !defined (speakerPin2)
#define speakerPin2 12
#endif
#if defined (ENABLE_LED)
#define ledPin 13
#endif
#else //Speaker selection for Uno,Nano, etc
#if !defined (speakerPin)
#define speakerPin 9 //The pins to output audio on. (9,10 on UNO,Nano)
#endif
#if !defined (speakerPin2)
#define speakerPin2 10
#endif
#if defined (ENABLE_LED)
#define ledPin 6
#endif
#endif
//********Radio Defines ****************************
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[14] = { 0xABCDABCD71LL, 0x544d52687CLL, 0x544d526832LL, 0x544d52683CLL,0x544d526846LL, 0x544d526850LL,0x544d52685ALL, 0x544d526820LL, 0x544d52686ELL, 0x544d52684BLL, 0x544d526841LL, 0x544d526855LL,0x544d52685FLL,0x544d526869LL};
Bien pues quiero añadirle una pantalla LCD pero al no tener pines suficientes la añado gracias al circuito integrado 74HC595N, utilizando sólo 3 pines del Arduino. Al principio los conecté a los pines digitales 2, 4 y 5, e introduciendo sólo el código de la LCD + 74HC595N funciona:
#include <Wire.h>
#include <LiquidCrystal_SR3W.h>
const int PIN_LCD_STROBE = 4; // Out: LCD IC4094 shift-register strobe LACH PIN - STCP
const int PIN_LCD_DATA = 2; // Out: LCD IC4094 shift-register data DATA PIN - DS
const int PIN_LCD_CLOCK = 5; // Out: LCD IC4094 shift-register clock CLOCK PIN - SHCP
LiquidCrystal_SR3W lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE); // srdata / srclock / strobe
// Creat a set of new characters
byte armsUp[8] = {0b00100,0b01010,0b00100,0b10101,0b01110,0b00100,0b00100,0b01010};
byte armsDown[8] = {0b00100,0b01010,0b00100,0b00100,0b01110,0b10101,0b00100,0b01010};
void setup(){
lcd.begin(16,2); // initialize the lcd
lcd.createChar (0, armsUp); // load character to the LCD
lcd.createChar (1, armsDown); // load character to the LCD
lcd.home (); // go home
lcd.print("WALKIE-TALKIE");
}
void loop(){
// Do a little animation
for(int i = 0; i <= 15; i++) showHappyGuy(i);
for(int i = 15; i >= 0; i--) showHappyGuy(i);
}
void showHappyGuy(int pos){
lcd.setCursor ( pos, 1 ); // go to position
lcd.print(char(random(0,2))); // show one of the two custom characters
delay(550); // wait so it can be seen
lcd.setCursor ( pos, 1 ); // go to position again
lcd.print(" "); // delete character
}
Se ve correctamente, el problema viene al intentar unir los dos códigos, de esta manera (está puesto para verse Walkie-Talkie en la pantalla pero nada):
#include <RF24.h>
#include <SPI.h>
#include <RF24Audio.h>
#include "printf.h"
#include "userConfig.h"
#include <Wire.h>
#include <LiquidCrystal_SR3W.h>
//*******************************************************************************
const int PIN_LCD_STROBE = 15; // Out: LCD IC4094 shift-register strobe LACH PIN - STCP //LCD
const int PIN_LCD_DATA = 18; // Out: LCD IC4094 shift-register data DATA PIN - DS //LCD
const int PIN_LCD_CLOCK = 19; // Out: LCD IC4094 shift-register clock CLOCK PIN - SHCP //LCD
LiquidCrystal_SR3W lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE); // srdata / srclock / strobe //LCD
//*******************************************************************************
RF24 radio(7,8);
RF24Audio rfAudio(radio,0);
int talkButton = 3;
void setup() {
Serial.begin(115200);
printf_begin();
radio.begin();
radio.printDetails();
rfAudio.begin();
pinMode(talkButton, INPUT);
attachInterrupt(digitalPinToInterrupt(talkButton), talk, CHANGE); //Interrupcción en modo de cambio (CHANGE)
rfAudio.receive();
//****************************************************************************
lcd.begin(16,2); // initialize the lcd
//****************************************************************************
}
void loop() {
lcd.setCursor(0,0);
lcd.print("WALKIE-TALKIE");
lcd.setCursor(0,1);
lcd.print("WALKIE-TALKIE");
}
void talk()
{
if (digitalRead(talkButton)) rfAudio.transmit();
else rfAudio.receive();
}
Con este código los Arduinos siguen transmitiéndose información pero la pantalla LCD se queda en blanco, no sé por qué, no sé qué tipo de conflicto habrá en el código o si es por las librerías. Si me podéis echar una mano os lo agradeceré mucho. Perdón por tanto código, gracias de antemano y un saludo.