-
-
I did:
phValue = phValue.substring(0, phValue.length - 1);
That code removes the last character as expected.
In my previous forum post I explained that I attempted to catch the \r by doing:
if (e.data != "\r" || e.data != "\n") { console.log("NO CR"); phValue+=e.data; }
However, "NO CR" is echoing out 5 times instead of only 4. I have no idea why \r is getting stored to the phValue when the if statement I think should of filtered \r out. Can anyone explain why this is happening?
-
I read through the reference section of this website and could not find a trim or some sort of replace function. The issue I am having is, my PH sensor responds with a float(ie 8.55) with a length of 5. I think the fifth character is a carriage return. I could not tell so I used String.charCodeAt(5) which responded back with a 13. How do I remove the \r or any none digit character from the end of the float value? Since the value is sent via serial communication I tried:
If (e.data != "\r" || e.data != "\n") { phValue = e.data; }
However, when I check the length of the phValue again I am still getting a length of 5.
-
ha! I figured it out :-) apparently GPIO4 is not the actual pin "4". GPIO4 is actually pin "13". Oops.
@DrAzzy, I think you should purchase the wifly module. It is well worth the money :)
-
DrAzzy I asked for help in the microchip.com forums. Hopefully I get a response back(keeping fingers crossed).
@DrAzzy just so I understand this, here is some code that wrote to get the status of a specific pin.
function readPin() { var dr = A8.read(); console.log(dr); }
If the dr variable returns a "true" that means the A8 pin is reading some sort of load? If dr returns "false" that means the A8 pin is NOT reading any load?
-
pinMode(A8, 'input_pulldown');
Worked as expected, but that is half the battle. When I remove the power from the wifly module I receive 'false'. When I reattach the power to the wifly module I receive 'true'. If you are familiar with the wifly module, to disconnect from a connected access point, you need to send the command "leave\r" while in cmd mode. I did just that, but I am still receiving a 'true'. Which led me to believe I did not change the GPIO4 pin functionality from LED to a GPIO. Changing the functionality from LED to GPIO is what I am having issues with. I am not sure how to achieve that. I read through the user manual, but I am still unsure how to achieve that.
-
DrAzzy, from my understanding the wifly GPIO 4 pin should be high when the wifly is connected to an access point, then the pin will go low when not connected. I need to, if at all possible, check the "status" of the GPIO4 pin using the Espruino. I will have to try your idea when I get home from work.
-
I tried using digitalRead(A8) and A8.read(). digitalRead returned a 1 and read() returned true. I still get the same results when the power is disconnected from the wifly module. I thought the A8 pin would return false or 0 since GPIO4 of the wifly pin is no longer set to HIGH when the power is disconnected.
-
I set up my wifly to auto connect to my access point and connect to my website when data is received at the wifly rx pin. On page 63(not 100% sure) of http://ww1.microchip.com/downloads/en/DeviceDoc/rn-wiflycr-ug-v1.2r.pdf it explains the alternate functionality of GPIO4. I would like to enable the alternate functionality of GPIO4 so the Espruino can monitor if the wifly is connected to the Access Point or not. Even though the manual explains how to achieve changing GPIO4 functionality I am still unsure what the bit code and command I am needing to use. Also, how do I setup a pin on the Espruino to check the status of the GPIO4 pin of the wifly?
-
@motter For your temperature sensor, checkout https://www.atlas-scientific.com/product_pages/sensors/env-tmp.html and for an example on how to get the temp probe to work with the espruino, http://forum.espruino.com/conversations/680/newest/ .
-
-
-
-
DrAzzy, yes the temp is averaging around -20C. I don't think it is a wiring issue. I was getting positive readings before I attempting to implement some kind of averaging temp reading. Well, I just made a liar out of myself. I went back to my original code without the averaging stuff and I am still receiving negative readings.
Original code:
function onInit() { var phValue=""; Serial4.setup(38400); Serial4.onData(function (e) { phValue+=e.data; if (e.data == "\r") { console.log(phValue); phValue=""; } }); function getResTempValue() { var vOut = E.getAnalogVRef() * analogRead(A0); // if you attached VOUT to Ao var vZero = 0.4; var tCoeff = 19.5 / 1000; var temp = (vOut - vZero) / tCoeff; console.log(temp); return temp.toFixed(2); } function getPhValue() { var rescomp=""; var pfloat=""; //on = !on; //digitalWrite(LED1, on); rescomp = getResTempValue(); pfloat = parseFloat(rescomp); console.log("Temp: " + pfloat); Serial4.print(rescomp+"\r"); //Serial4.print("r\r"); } function phCalibrate4() { } function phCalibrate7() { } function phCalibrate10() { } var interval = setInterval(getPhValue, 5000); } onInit();
-
Hi Gordon. Setting both the variables to 0 worked. I am now receiving a negative temp reading. It has to be my math that is the issue.
Code:
function getResTempValue(x) { var temp=0; var avgTemp=0; for (var i=0;i<x;i++) { var vOut = E.getAnalogVRef() * analogRead(A0); // if you attached VOUT to Ao var vZero = 0.4; var tCoeff = 19.5 / 1000; var tempinc = (vOut - vZero) / tCoeff; var tempinf = tempinc * (9 / 5) + 32; temp = temp + tempinc; console.log(temp); if (i==x) { //avgTemp = temp / x; //temp = temp / x; } console.log(i); } temp = temp / x; console.log("Temp: " + temp + "Avg temp: " + avgTemp); return temp.toFixed(2); }
-
I am now attempting to get a more accurate result by finding the average of multiple temp results. The issue I am having is, when I find the average I am getting undefined and NaN from the output of the variable that I supposedly saved the average to. The issue I think is stemming from the way I am saving the temp value. Also, besides taking the average results, is there another way I could achieve a more accurate temperature?
My code:
function getResTempValue(x) { var temp; var avgTemp; for (var i=0;i<x;i++) { var vOut = E.getAnalogVRef() * analogRead(A0); // if you attached VOUT to Ao var vZero = 0.4; var tCoeff = 19.5 / 1000; var tempinc = (vOut - vZero) / tCoeff; var tempinf = tempinc * (9 / 5) + 32; temp = temp + tempinc; console.log(temp); if (i==x) { avgTemp = temp / x; temp = temp / x; } console.log(i); } console.log("Temp: " + temp + " Avg temp: " + avgTemp); return temp.toFixed(2); } //IE getResTemp(5);
-
-
-
-
In my past projects I have successfully used a MCP9701. Atlas-scientific has created a wonderful waterproof and food friendly product that incorporates the MCP9701. I emailed the manufacturer for more info about their product. They responded that their product uses a "MCP9701 and other stuff" in the past I had to modify their arduino example code to work with the mbed platform with success. Now, I would like to port/modify the arduinos example code to work on the Espruino platform. I stumbled across http://www.espruino.com/Thermistors. I am not sure of the mcp chip that I am using will work when using the Espruino thermistors example. The example page asked to check the resistance then use a matching resistor. I have never used a resistor with my past projects using a arduino and mbed because the datasheet of the temp probe https://www.atlas-scientific.com/_files/_datasheets/_sensor/ENV-TEMP_1.4.pdf never asked to use one. maybe the resister is already part of the atlas-scientific temp probe? I'm looking for guidance to port the code over to Espruino, any help is greatly appreciated.
-
-
-
Gordon, thanks for responding. When I plug the Espruino board into a USB port, should windows 7 find the device and mount it like a regular USB device? If that is the case, windows is not mounting the device so I cannot copy files to the sdcard. I'm not sure if that is the way to load external .j's file to the sdcard for future usage.
-
I read through the troubleshoot section of the Espruino Website and found the answer to my locking up issues. I switch back to 1.52 of the firmware. Even though I still get the error mentioned in my original post, the code still executes as expected.
Thanks Gordon for taking the time to fix that bug. I'm looking forward to the next updated firmware.
That was exactly the issue. I read the sensor module user guide again, it explained the results will end in a "\r". So I removed the checking for the newline character. As soon as I removed the newline check and only checked for a CR:
It worked. When I get home from work I will implement your example.