-
-
I have some simple temperature display code which is giving me grief when I save() it to the Espruino. The code continues to run after a reset or power cycle but the characters are barely visible on the screen. It's like the contrast is turned down to almost zero. It works and displays fine when the same code is just uploaded and run directly. I've read all the threads about using onInit() but it's not helping at all.
Any ideas? Code looks identical in both cases using dump() apart from the contents of g.buffer;
Thanks
var g; var rtc; var numReadings = 10; var temperatures = []; var index; // the index of the current reading var total; // the running total var average; // the average function onInit() { index = 0; // the index of the current reading total = 0; // the running total average = 0; SPI1.setup({ baud: 1000000, sck:B3, mosi:B5 }); clearInterval(); // initialize all the readings to 0: for (i = 0; i < numReadings; i++){ temperatures[i] = 0; } digitalWrite(B13,0); I2C2.setup({scl:B10,sda:B11}); rtc = require("DS3231").connect(I2C2); // setInterval(function() { // console.log(rtc.readDateTime()); // }, 1000); g = require("PCD8544").connect(SPI1,B6,B7,B8, function() { g.clear(); g.setContrast(0.45); g.flip(); // copy this to the screen setInterval(onTimer, 1000); }); } function onTimer() { // subtract the last reading: total = total - temperatures[index]; var val = analogRead(C0); temperatures[index] = (((val*3.3)-1.25)/0.005); //console.log("Total: " + total); //console.log("Temperature: " + temperatures[index]); // add the reading to the total: total = total + temperatures[index]; // advance to the next position in the array: index = index + 1; // if we're at the end of the array... if (index >= numReadings){ // ...wrap around to the beginning: index = 0; } // calculate the average: average = total / numReadings; //console.log("Average: " + average); g.clear(); g.setContrast(0.45); g.setFontBitmap(); // simple 8x8 font g.setFontVector(20); // large font g.drawString(average.toFixed(2), 0, 0); g.drawString("C", 65, 0); g.setFontVector(15); // large font var localtime = rtc.readDateTime().split(" ")[1]; g.drawString(localtime, 0, 32); g.flip(); // copy this to the screen } onInit();
-
-
@ArthurGuy I finally got back to trying this out again and made some progress. I can now successfully transmit from Arduino to Espruino completely reliably.
On Espruino:
SPI1.setup({ sck: A5, miso: A6, mosi: A7 } ); var nrf = exports.connect( SPI1, B0, B1 ); var counterCheck=0; function onInit() { nrf.init([0xF0,0xF0,0xF0,0xF0,0xF0], [0xF0,0xF0,0xF0,0xF0,0xF0]); } onInit(); dataLine = ""; setInterval(function() { while (nrf.dataReady()) { var data = nrf.getData(); for (var i in data) { var ch = data[i]; if ((ch===0 || ch==0x0A) && dataLine!=="") { console.log(dataLine); dataLine = ""; } else if (ch!==0) { dataLine += String.fromCharCode(ch); } } } }, 50);
On Arduino:
// Set up nRF24L01 radio on SPI pin for CE, CSN RF24 radio(8,9); // Example below using pipe5 for writing const uint64_t pipes[2] = { 0xF0F0F0F0F0LL, 0xF1F1F1F1F1LL }; //radio.enableDynamicPayloads(); radio.setPayloadSize(0x10); radio.setDataRate(RF24_2MBPS); radio.setPALevel(RF24_PA_MAX); radio.setChannel(2); radio.setRetries(15,15); radio.setCRCLength(RF24_CRC_8); radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]);
The only change I really made since previously was to set the Payload to 16 on Arduino as suggested by @Gordon. I also tried setting Dynamic Payload in both cases and that seems to work too.
However making the Arduino the receiver and the Espruino the transmitter is proving more difficult. The Arduino says that it has received a payload every time one is sent from the Espruino, but the contents are all zeros. The Espruino also gives a "TX not received 82" after every transmit.
So at least we know there is no fundamental incompatibility here but I'm running out of ideas on the Arduino-RX side of things.
-
Thanks Gordon, I've done a lot of playing with addresses at both ends as per the IC spec without much luck. I've been trying to make Arduino settings more like Espruino, but as you suggest, maybe the other way around might be better. I'll play more this week. Will do pull request if I get to the bottom of it.
-
-
I've been struggling with exactly the same setup and libraries. I've ended up dumping out the register contents of the NRF24L01+ from both the Espruino side and the Arduino side and tried to line them up. There were some basic differences like bit rate and channel which I've sorted out but still almost no joy. I've managed to go from silence to maybe one transmit in 30 or 40 being received by the Arduino if the Espruino is sender and similar success rate if I swap them around.
The RF24 Arduino code works perfectly on a mix of Pro Minis, Unos and DigiX but just getting no joy on Espruino. The only thing I can think of at the moment, in lieu of an oscilloscope, is to get a second Espruino and see if they can at least see each other.
Register Dump from Arduino:
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xfefefefefe 0x2222222222
RX_ADDR_P2-5 = 0x02 0x03 0x04 0x05
TX_ADDR = 0xfefefefefe
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3f
EN_RXADDR = 0x3f
RF_CH = 0x02
RF_SETUP = 0x0f
CONFIG = 0x0b
DYNPD/FEATURE = 0x00 0x00
Data Rate = 2MBPS
Model = nRF24L01+
CRC Length = 8 bits
PA Power = PA_MAXRegister Dump from Espruino:
STATUS = 0xE
RX_DR = 0x0
TX_DS = 0x0
MAX_RT = 0x0
RX_P_NO = 0x7
TX_FULL = 0x0
RX_ADDR_P0 = 0,0,0,0,1
RX_ADDR_P1 = 0,0,0,0,2
RX_ADDR_P2 = 195,195,195,195,195
RX_ADDR_P3 = 196,196,196,196,196
RX_ADDR_P4 = 197,197,197,197,197
RX_ADDR_P5 = 198,198,198,198,198
TX_ADDR = 0,0,0,0,1
RX_PW_P0 = 0x10
RX_PW_P1 = 0x10
RX_PW_P2 = 0x0
RX_PW_P3 = 0x0
RX_PW_P4 = 0x0
RX_PW_P5 = 0x0
RX_PW_P6 = 0xB
EN_AA = 0x3F
EN_RXADDR = 0x3
RF_CH = 0x2
RF_SETUP = 0xF
CONFIG = 0xB
DYNPD = 0x0
FEATURE = 0x0
Data Rate = 2MBPS
CRC Length = 8
PA Power = MAX -
Just a quick FYI that current code compiles with no changes on Cygwin for Windows and so far is running perfectly. See http://conoroneill.net/run-the-espruino-js-interpreter-on-windows/
That makes a lot of sense. Thanks. I'll try as soon I collect the turkey :-)
I wondered about the OnInit(). It's in most of the examples I saw but I wondered if it was auto-called. I'll comment it out again.