I'm currently working on a project: (Project Guidance Forum Post)
my current problems with the project are programming related so I thought I'd make a post here (sorry if this is an incorrect forum etticitte)
I was trying to use an arduino Mega to interface with a 7" RA8875 display from adafruit. I've been able to build my UI with no issues (minus lack of font to be honest - another issue for another day)
because I know this display has issues being in a tri - state i was going to use a pro - mini to handle all the wireless communication. But the moment I enabled the serial.begin(9600) radio communication would stop. I tried this on another nano without the external antenna version of the nRF24. and a nano in the same configuration with the same result.
after some research I was starting to wonder if using SPI and UARt was a limitation for the nano / pro mini. But likely something the MEGA could multitask. While I didn't find a definitive answer to that when doing research I decided to try controlling the nRF24 directly with the mega using software SPI on the nRF24 to narrow down the issue. While i can get the nRF24 to work of SOFTSPI, the moment I uncomment #include "Adafruit_RA8875.h" the wireless stops responding. I've tried changing the speeds within each library and haven't seen any change in behavior.
any thoughts suggestions / parts to try would be greatly appreciated.
transmit code:
#include <SPI.h>
#include <Wire.h>
#include "nRF24L01.h" //NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "DigitalIO.h"
#include "Adafruit_GFX.h"
//#include "Adafruit_RA8875.h"
#include <Adafruit_NeoPixel.h>
RF24 radio(24,22); // ce, cs // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO
#define num_modules 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(num_modules, 5, NEO_GRBW + NEO_KHZ800);
//#define RA8875_CS 53
//#define RA8875_RESET 9
//Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
int i = 0;
int v = 0;
//RF24 radio(24,22); // ce, cs // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO
const byte pipe = "000001"; // Needs to be the same for communicating between 2 NRF24L01
/////// data to be changed for sending and receiving
unsigned long patternInterval1 = 50 ; // time between steps in the pattern
unsigned long patternInterval2 = 75 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
struct Data_Package {
byte MODE_num;
byte LED_num;
uint32_t color;
uint8_t music1;
uint8_t music2;
uint8_t music3;
uint8_t music4;
uint8_t music5;
};
Data_Package data;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
radio.begin(); // Start the NRF24L01
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(pipe); // Get NRF24L01 ready to transmit
radio.setAutoAck(false);
data.MODE_num = 0;
data.LED_num = 0;
data.color = 0;
/*
if (!tft.begin(RA8875_800x480)) {
while (1);
}
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.fillScreen(RA8875_BLACK);
tft.textMode();
*/
}
void loop() {
// put your main code here, to run repeatedly:
colorSET(strip.Color(0,255,0,0));
delay(200);
colorSET(strip.Color(255,0,0,0));
delay(200);
colorSET(strip.Color(0,0,255,0));
delay(200);
}
void updating(){
// SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
radio.write(&data, sizeof(Data_Package));
radio.write(&data, sizeof(Data_Package));
radio.write(&data, sizeof(Data_Package));
// SPI.endTransaction();
}
void colorSET(uint32_t c) {
for(uint16_t i=1; i<num_modules; i++) {
data.LED_num = i;
data.color = c;
updating();
}}
The receiver code (the lights)
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 1 // Number of leds on stick
#define PIN 3 // Digital In (DI) of RGB Stick connected to pin 8 of the UNO
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
RF24 radio(9,10); // NRF24L01 used SPI pins + Pin 9 and 10 on the UNO
const byte pipe = "000001"; // Needs to be the same for communicating between 2 NRF24L01
struct Data_Package {
byte MODE_num;
byte LED_num;
uint32_t color;
uint8_t music1;
uint8_t music2;
uint8_t music3;
uint8_t music4;
uint8_t music5;
};
Data_Package data;
int n;
uint32_t color_recieved = 0;
/////////////////////////////////////////////////////
//
// these varaible need to be changed for each module
//
/////////////////////////////////////////////////////
#define module_num 5 // (between 1 - 50) // sets color channel
//#define music_num 4 // (between 1 - 5) // sets music channel
// set the music color
uint32_t music_color = strip.Color(0,0,data.music5,0);
void setup(void){
strip.begin();
strip.show(); // Initialize all pixels to 'off'
radio.begin(); // Start the NRF24L01
radio.openReadingPipe(1,pipe); // Get NRF24L01 ready to receive
radio.setAutoAck(1,false);
radio.startListening(); // Listen to see if information received
data.LED_num = 0;
data.color = 0;
strip.setPixelColor(0,0,0,0,50);
strip.show();
delay(500);
// strip.setPixelColor(0,0,0,0,50);
// strip.show();
}
void loop(void){
while (radio.available()){
radio.read(&data, sizeof(Data_Package)); // Read information from the NRF24L01
if (data.MODE_num == 0){
if (data.LED_num == module_num){
color_recieved = data.color;
}}
if (data.MODE_num == 1){ // activate music mode
// uint32_t music_color = strip.Color(0,0,0,0);
color_recieved = music_color;
} // end of msuic mode
}
strip.setPixelColor(0,color_recieved);
strip.show();
} // end loop