-
My Espruino died today. When plugging in the USB or battery it did not seem to work. Trying to enter boot loader mode did not work and no flickering from the LED's. I measured voltage levels on batt and 3.3 with USB plugged in. Bat was 4.9 volts 3.3pin reads 0.7 volts. If I connected a 3.3 volt power source to the 3.3v pin next to bat the espruino works and I am able to send commands from the serial console via USB. Is there a fuse on the board or which component number is the voltage regulator?
-
-
var cmd=""; var issued_command=""; Serial4.setup(9600,{rx:C11,tx:C10}); //Parse response v2 function parse(buffer){ var line = buffer.toString().substring(0, buffer.length - 1); //Remove anything remotely blank or echoey if(line.length < 2 || line.indexOf(">")===0 || issued_command===line){ return; } issued_command=""; //SMS Received if(line.indexOf("+")>-1){ var d = line.substr(line.indexOf("+")+1,line.indexOf(":")-1); switch(d) { case "CMTI": tnum = line.split(","); console.log("SMS received #", tnum[1]); setTimeout(function(){send_command("at+cmgr="+tnum[1]+"\r");},1000); break; //read incoming SMS case "CSQ": sgnl = line.slice(5); sgnl = sgnl.split(","); console.log("signal strength "+sgnl[0]); //console.log(line); break; //Read cell signal case "CMGL": //console.log("all text messages in memory "); break; //View all text message in memory case "CMGR": console.log("text message "+line); break; //read individual text message in memory case "COPS": ntwk = line.slice(5); ntwk = ntwk.split(","); console.log("network "+ ntwk[2]); break; //Read network carrier case "CBC": chg = line.split(","); console.log("battery charge " + chg[1] + "% + " + chg[2] + "mv's"); break; //read battery charge } } //Turn on LED's if command sent! else if (line.indexOf("Lights on")>-1) { console.log("do something"); LED.write(1); LED2.write(1); } //Turn off LED's if command sent. else if (line.indexOf("lights off")>-1) { LED.write(0); LED2.write(0); } else { //Response Received console.log("Parsed: " + line); }} //Serial on data v2 Serial4.on('data',function(data){ cmd += data; var id = cmd.indexOf("\n"); while (id>=0){ var line = cmd.substr(0,id); cmd=cmd.substr(id+1); parse(line); id=cmd.indexOf("\n"); } }); // get network carier function get_network() { setTimeout(function(){send_command("at+cops?\r");},200); } //get signal strength function get_signal() { setTimeout(function(){send_command("at+csq\r");},200); } //read all texts in memory function read_all_text() { setTimeout(function(){send_command("at+cmgl=\"all\"\r");},200); } //bet battery % charge and voltage function get_voltage() { setTimeout(function(){send_command("at+cbc\r");},200); } function Send_SMS(text) { Start_GSM(); setTimeout(function(){send(text);},1000); } //Start the GSM Module function Start_GSM() { console.log("GSM Starting..."); pinMode(C0,"output"); digitalPulse(C0,1,2000); setTimeout(function(){send_command("at+cmgf=1\r");},1000); } function Stop_GSM(){ pinMode(C0,"output"); digitalPulse(C0,1,2000); } function send(input){ setTimeout(function(){send_command("AT+CMGS=\"xxxxxxxxxx\"\r");},2000); setTimeout(function(){send_command(input);},3000); setTimeout(function(){send_command("\x1A\r");},3500); setTimeout(function(){Stop_GSM();},10000); } function send_command(command){ //Set the command that we are sending to issue_command for later parse out issued_command=command; //Send the command to serial port connected to GSM Serial4.write(command); //Output what we sent to console console.log("Command Sent:" + command); } function onInit(){ // send SMS when BTN pressed setWatch(function(e) { Send_SMS("Saying hello! "); }, BTN, { repeat:true, edge:'falling', debounce:20 }); //Send_SMS("Saying hello "); } onInit();
-
-
Will work on the Switch code and share when I have a few minutes free. This should take care of the differing responses based on different commands. A if statement before the switch statement should be able to check the expected response vs actual response.
The Digital.write code that Gordon posted above still does not seem to work correctly. I think rather than using a delay time after the 2 second high turn on code is run, the right way to handle this is to read a pin on the modem that lights up the ready LED to make sure the modem is ready to read commands.
This is fun stuff!
-
Took another look at the Serial.write cmd. I had the / \ mixed up. Now it seems to work.
On to the issue of reading and processing the send command output. Would a swicth statement in the serial.on("data") make sense?
if I send the command Serial.write("AT+CBC\n\r", 500, "+CBC",function(){}); to check the battery voltage I get +cbc: 0,94,3978 returned from the serial port. With a switch statement I could act on this by parsing the +cbc from the line and comparing it to the expected response from the Serial.write line (+CBC). If these agree I could then return an array for the 0,94,3878, that shows battery % charge left and the battery voltage.
I will try to code this later today if someone agrees this is a good way to proceed.
-
-
Fona also requires 2 second high pulse to turn on/off board. I have might not explained correctly but when I run Gordon's code the digitalPulse command does not seem to block. Hence the other AT commands to initialize the board are sent before the GSM board is powered on.
Thinking about his maybe the Send_Command in the start_GSM function needs to be fired from a SetTimeout command that waits for 2 seconds to allow for the GSM board to be powered on. That way the commands are sent and read rather than being lost.
I think most GSM boards are going to have the same command set so once the code is working it will be relevant to a number of GSM boards.
-
I am also trying same test. As well as serial setup I see a few other things that I dont quite understand. Does espruino have a blocking timeout command? when setting c0 high for 2 seconds using digitalPulse does not block I tried using setTimeout(function(){},2000); after digitalPulse, the code continues and sends AT commands before the GSM unit turns on.
I am struggling to understand how the responseCallback routine works.
I am finding it really interesting to read and try to debug code. It gives a much better understanding of the way that Javascript works.
-
-
-
-
In case this information helps. I tried changing the speed of the other GPS unit from 57600 to 9600 baud. It still did not work. I believe the reason for this is the period of the updates rather than the baud rate. The two GPS units that I am using are the Adafruit Ultimate GPS and a LS20031. So I think the issue is the 5hz output set from the factory on the LS20031.
-
-
I am able to get data out of the GPS by calling variables from the command line. I am unable to control the LCD manually when the GPS is running but am able to do so when I comment out the GPS code.
So it seems that somehow the GPS code is preventing the LCD code from working. Although the code is similar to the Walking GPS code on the site.
I am running at 57600 baud as thats how the GPS I am using is configured. I can try another unit that operates at 9600 baud although it has a smaller antenna. Maybe the rapid update on the GPS is preventing the LCD screen from re loading.
-
I am fairly new to Javascript and am trying to understand why I am having an issue displaying gps data on a PCD8544. If I comment out the GPS code the display will characters. When the GPS code is included the LCD screen does not display any characters. I tried converting the lat1 variable from number to string but that did not work. WHat am I doing wrong?
A2.write(0); // GND A4.write(1); // VCC SPI1.setup({ baud: 2000000, sck:A5, mosi:A7 }); var g; function onInit() { g = require("PCD8544").connect(SPI1,A6,B0,B1, function() { g.clear(); g.drawString("Hello",0,0); g.drawLine(0,10,84,10); g.flip(); }); } onInit(); Serial4.setup(57600,{tx:C10,rx:C11}); var gps = require("GPS").connect(Serial4, function(data) { lat1 = data.lat; g.clear(); g.drawString(lat1,0 ,0); g.flip(); });
-
-
Trying to run the example code for the PCD8544 and get the following error. Looks like it is a problem in the module. How can I fix this?
SPI1.setup({ baud: 2000000, sck:A5, mosi:A7, order:'msb' }); var g; function onInit() { g = require("PCD8544").connect(SPI1,A6,C1,C3);} function lcd() { g.clear(); g.drawString("Hello",0,0); g.drawLine(0,10,84,10); g.flip(); } >onInit() ERROR: Using '.' operator on non-object at line 1 col 16 {var a=Graphics.createArrayBuffer(84,48,1,{vertical_byte:!0});setTimeout(function(){digitalWrite(c,0);digitalPulse(f,0,10);setTimeout(function(){b.send([33,191,20,6,32,12],d);void 0!==e&&e()},100)},100);a.flip=function(){digitalWrite(c,0);b.send([64,128],d);digitalWrite(c,1);b.send(this.buffer,d)};a.setContrast=function(a){digitalWrite(c,0);b.send([33,128|Math.clip(127*a,0,127),32,12],d)};return a} ^ at line 1 col 34 {var a=Graphics.createArrayBuffer(84,48,1,{vertical_byte:!0});setTimeout(function(){digitalWrite(c,0);digitalPulse(f,0,10);setTimeout(function(){b.send([33,191,20,6,32,12],d);void 0!==e&&e()},100)},100);a.flip=function(){digitalWrite(c,0);b.send([64,128],d);digitalWrite(c,1);b.send(this.buffer,d)};a.setContrast=function(a){digitalWrite(c,0);b.send([33,128|Math.clip(127*a,0,127),32,12],d)};return a} ^ in function "connect" called from line 2 col 47 in function "onInit" called from line 1 col 8
My Espruino died today. When plugging in the USB or battery it did not seem to work. Trying to enter boot loader mode did not work and no flickering from the LED's. I measured voltage levels on batt and 3.3 with USB plugged in. Bat was 4.9 volts 3.3pin reads 0.7 volts. If I connected a 3.3 volt power source to the 3.3v pin next to bat the espruino works and I am able to send commands from the serial console via USB. Is there a fuse on the board or which component number is the voltage regulator?