carachen1220 / Art-Art-Art

0 stars 1 forks source link

UNO R4 WIFI not working #2

Closed Henrrrrrry closed 2 weeks ago

Henrrrrrry commented 2 weeks ago

code:

include

include "SSD1X06.h"

/* nRF24L01+ module connections

// the nRF24L01+ can tune to 128 channels with 1 MHz spacing from 2.400 GHz to 2.527 GHz.

define CHANNELS 128

// SPI definitions and macros

define CE_pin 9

define CS_pin 10

define MOSI_pin 11

define MISO_pin 12

define SCK_pin 13

define CE_on digitalWrite(CE_pin, HIGH)

define CE_off digitalWrite(CE_pin, LOW)

define CS_on digitalWrite(CS_pin, HIGH)

define CS_off digitalWrite(CS_pin, LOW)

define MOSI_on digitalWrite(MOSI_pin, HIGH)

define MOSI_off digitalWrite(MOSI_pin, LOW)

define MISO_on digitalRead(MISO_pin) // input

define SCK_on digitalWrite(SCK_pin, HIGH)

define SCK_off digitalWrite(SCK_pin, LOW)

// nRF24 Register map enum { NRF24L01_00_CONFIG = 0x00, NRF24L01_01_EN_AA = 0x01, NRF24L01_02_EN_RXADDR = 0x02, NRF24L01_03_SETUP_AW = 0x03, NRF24L01_04_SETUP_RETR = 0x04, NRF24L01_05_RF_CH = 0x05, NRF24L01_06_RF_SETUP = 0x06, NRF24L01_07_STATUS = 0x07, NRF24L01_08_OBSERVE_TX = 0x08, NRF24L01_09_CD = 0x09, NRF24L01_0A_RX_ADDR_P0 = 0x0A, NRF24L01_0B_RX_ADDR_P1 = 0x0B, NRF24L01_0C_RX_ADDR_P2 = 0x0C, NRF24L01_0D_RX_ADDR_P3 = 0x0D, NRF24L01_0E_RX_ADDR_P4 = 0x0E, NRF24L01_0F_RX_ADDR_P5 = 0x0F, NRF24L01_10_TX_ADDR = 0x10, NRF24L01_11_RX_PW_P0 = 0x11, NRF24L01_12_RX_PW_P1 = 0x12, NRF24L01_13_RX_PW_P2 = 0x13, NRF24L01_14_RX_PW_P3 = 0x14, NRF24L01_15_RX_PW_P4 = 0x15, NRF24L01_16_RX_PW_P5 = 0x16, NRF24L01_17_FIFO_STATUS = 0x17, NRF24L01_1C_DYNPD = 0x1C, NRF24L01_1D_FEATURE = 0x1D, //Instructions NRF24L01_61_RX_PAYLOAD = 0x61, NRF24L01_A0_TX_PAYLOAD = 0xA0, NRF24L01_E1_FLUSH_TX = 0xE1, NRF24L01_E2_FLUSH_RX = 0xE2, NRF24L01_E3_REUSE_TX_PL = 0xE3, NRF24L01_50_ACTIVATE = 0x50, NRF24L01_60_R_RX_PL_WID = 0x60, NRF24L01_B0_TX_PYLD_NOACK = 0xB0, NRF24L01_FF_NOP = 0xFF, NRF24L01_A8_W_ACK_PAYLOAD0 = 0xA8, NRF24L01_A8_W_ACK_PAYLOAD1 = 0xA9, NRF24L01_A8_W_ACK_PAYLOAD2 = 0xAA, NRF24L01_A8_W_ACK_PAYLOAD3 = 0xAB, NRF24L01_A8_W_ACK_PAYLOAD4 = 0xAC, NRF24L01_A8_W_ACK_PAYLOAD5 = 0xAD, };

// Bit mnemonics enum { NRF24L01_00_MASK_RX_DR = 6, NRF24L01_00_MASK_TX_DS = 5, NRF24L01_00_MASK_MAX_RT = 4, NRF24L01_00_EN_CRC = 3, NRF24L01_00_CRCO = 2, NRF24L01_00_PWR_UP = 1, NRF24L01_00_PRIM_RX = 0,

NRF24L01_07_RX_DR       = 6,
NRF24L01_07_TX_DS       = 5,
NRF24L01_07_MAX_RT      = 4,

NRF2401_1D_EN_DYN_ACK   = 0,
NRF2401_1D_EN_ACK_PAY   = 1,
NRF2401_1D_EN_DPL       = 2,

};

// SPI Instruction Mnemonics

define R_REGISTER 0x00

define W_REGISTER 0x20

define REGISTER_MASK 0x1F

define ACTIVATE 0x50

define R_RX_PL_WID 0x60

define R_RX_PAYLOAD 0x61

define W_TX_PAYLOAD 0xA0

define W_ACK_PAYLOAD 0xA8

define FLUSH_TX 0xE1

define FLUSH_RX 0xE2

define REUSE_TX_PL 0xE3

define NOP 0xFF

enum TXRX_State { TXRX_OFF, TX_EN, RX_EN, };

uint16_t signalStrength[CHANNELS]; // smooths signal strength with numerical range 0 - 0x7FFF

void setup() { SSD1X06::start(); delay(300); SSD1X06::fillDisplay(' '); SSD1X06::displayString6x8(1, 4, F("2.4 GHz band scanner"), 0); SSD1X06::displayString6x8(4, 4, F("By ceptimus. Nov '16"), 0);

// Setup pins pinMode(MOSI_pin, OUTPUT); pinMode(SCK_pin, OUTPUT); pinMode(CS_pin, OUTPUT); pinMode(CE_pin, OUTPUT); pinMode(MISO_pin, INPUT);

// Initialize SPI SPI.begin();

CS_on; delay(10); NRF24L01_Reset(); delay(150);

NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // Disable ShockBurst mode NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, 0x0F); // Set default setup register value NRF24L01_SetTxRxMode(RX_EN); // Set to receive mode

for (int x = 0; x < 128; x++) { uint8_t b = 0x01; // baseline if (!(x % 10)) { b |= 0x06; // graduation tick every 10 MHz } if (x == 10 || x == 60 || x == 110) { b |= 0xF8; // scale markers at 2.41, 2.46, and 2.51 GHz } SSD1X06::displayByte(6, x, b); } SSD1X06::displayString6x8(7, 0, F("2.41"), 0

After changing the board from UNO WIFI (Not working since not the same model ) to the correspounding one (UNO R4 WIFI), it could successfully upload the code to the board but loop function doesn't work, I used serial.print to test but there's no output in serial monitor. Also I noticed before I upload the code, when there's no serial.print function, the serial monitor still can output average strength.

Henrrrrrry commented 2 weeks ago

We changed to Nano, so I'll close this issue