-
@DrAzzy I am glad that I posted a link to the N mosfet tutorial even though it was incorrect! As it looks like you have provided great information to the Espruino user community as a result. I don't see the photos that are referenced in the tutorial. Am I doing something wrong when viewing Github or are they not posted yet?
Thanks again for your informative post.
-
You might want to consider using a power Mosfet to switch on your light bulb like the one in the link below. They even reference switching on a car headlight with a 5v micro controller.
https://www.sparkfun.com/products/10213
Sparkfun sells a couple of breakout boards to switch loads using Mosfets.
https://www.sparkfun.com/products/11214
https://www.sparkfun.com/products/10256
p.s. I am not connected to this Sparkfun in any way other than being a customer.
If you want to control AC loads solid state relays seem to be simpler to interface with a microcontroller
-
-
-
I created this module today. It allows Espruino board to interface with a TMP102 temperature sensor. It is accurate down to 0.0625 of a degree.
I2C1.setup({scl:B6,sda:B7}); var TMP102 = require("tmp102").connect(I2C1); console.log(TMP102.getTemperature());
function TMP102(_i2c) { this.i2c = _i2c; this.address = 0x48; } TMP102.prototype.getTemperature = function() { var self = this; var d = self.i2c.readFrom(self.address, 2); var temp = (((d[0] << 8) | d[1]) >> 4)*0.0625; return temp; }; exports.connect = function (_i2c) { return new TMP102(_i2c); };
-
-
I tried out the code and it sort of works!
The only problem with including trtn.temp and trtn.fault in the same variable is the way the chip works. It supplies a 14 bit word that has temperature and fault information. Therefore when the fault flag is raised it still gives a temperature, just the wrong temperature. I included the if else statement in the earlier code to account for this. Maybe someone can suggest a way to accomplish with the trtn.temp and trtn.falut included in the same variable.
{"temp":2047.75,"fault":1,
"faultstring":"No probe detected"
}see the example above where no probe is detected yet the temperature is reported back as 2047.75C.
Ideally I think what is needed for simple example temperature measurement is the correct temperature or the fault condition.
-
I will test tomorrow but still think a couple of changes need to be made.
var d = SPI1.send("\0\0\0\0",C0); //needs to be changed to var d = this.spi.send("\0\0\0\0",this.cs);
This will allow more than one temp sensor to be connected and report temperature.
The else statement needs to be added back in at the end. See my code above. The reason for this is you only want the temperature reported if everything is ok. If a fault code is displayed then you only want that code. If not you get the fault code as well as a incorrect temperature reading. Once this is done I will test again and let you know if it works.
Really glad that I shared this code as I learnt a lot about OOP javascript today from everyones responses. Even though I have been reading a really good book on the subject, this thread really helped to cement all the pieces in place.
So thank you to all who responded.
-
This seems to have fixed the fault reporting issue.
exports.connect = function(spi,cs) { return new MAX31855(spi,cs); }; function MAX31855(spi,cs) { this.spi=spi; this.cs=cs; } MAX31855.prototype.getTemp = function () { var d = this.spi.send("\0\0\0\0",this.cs); var trtn={}; trtn.temp=(d.charCodeAt(0)<<6 | d.charCodeAt(1)>>2)*0.25; if (d.charCodeAt(1) & 1) { var fault = (d.charCodeAt(3) & 7); switch (fault) { case 1: return trtn.fault="No probe detected"; case 3: return trtn.fault="Probe shorted to Ground"; case 4: return trtn.fault="Probe shorted to VCC"; default: return trtn.fault=fault; } } else{ return trtn; }};
-
I have a old VW TDI that I have been experimenting with. Interestingly from my research they don't have a turbo pressure boost sensor, if they had it would be easiest just to tap directly into the sensor or the CAN network. It think that they calculate boost pressure using RPM and mass air flow sensor.
Ideally the easiest way to do this would have been to connect to the CAN and get boost pressure if VW had a boost sensor on the motor. I was able to do this on a Caterpillar large diesel engine using javascript and npm Can on a Beaglebone Black.
-
Thank you for putting this code into a module. I have been trying to understand OOP Javascript and just brought a book to try to wrap my head around it. Looking over this code as well as the comment from possman, It now fairly clear the way it works. Having scratched my head over this for a couple of weeks and now the light bulb in my brain turns on!
I did try the code and it partially works. It does report temperature correctly but the error reporting does not work correctly now. It only reports case 4 under all fault conditions. I will try to debug this and repost code later today.
-
I saw your trig code and figured it was engine related.
I actually wrote this code to measure engine exhaust gas temperature. You can buy temperature probes that are designed to work for this application
search type K EGT on ebay and you will find them for about $15.
I picked up a pressure sensor to measure turbo boost pressure. That sensor has a 0 - 40mv voltage swing from 0 - 29 psi. I now realize I should have looked harder to find one that had SPI or I2C interface as it would be easier to interface.
-
Gordon,
Thanks for your help.
Here is the code to interface espruino to a max31855 chip. The max31855 is connected to a thermocouple to measure high temperature up to 1300C. Feel free to use it to create a new module for Espruino.
//setup SPI port SPI1.setup({ miso:B4, sck:B3, baud:1000000 }); function getTemp() { //send command to get 32 bit word back from max31855 var d = SPI1.send("\0\0\0\0",C0); //calculate probe temperature eTemp = (d.charCodeAt(0)<<6 | d.charCodeAt(1)>>2)*0.25; //check for fault codes if (d.charCodeAt(1) & 1) { fault = (d.charCodeAt(3) & 7); switch (fault) { case 1: console.log("No probe detected"); break; case 3: console.log("Probe shorted to Ground"); break; case 4: console.log("Probe shorted to VCC"); break; default: break; } } else { //Print temperature console.log("EGT = "+eTemp + " C"); } } setInterval(getTemp, 250);
-
Finally got it to work!
Not sure what the problem was as I unsoldered everything and reassembled it. I was able to get output from the chip if I connected the logic analyzer to the pin of the chip before I disassembled. So I suspect it was a dry joint or something hardware related. Gordon thanks for your help. Will send you the code to add to modules when it is completed. Next job is to add a pressure transducer to the board.
-
-
-
-
I am trying to write code to connect a chip to the espruino but am really not getting how it works! I want to figure it out on my own but need some help. Hence the fact I am not stating what chip I am trying to interface too.
The chip has three lines SCK, MISO, and CS.
So I connect SCK to B3(sck on espruino), MISO to B5(miso on espruino)
CS is connected to C0
In the command line I write the following commands
///SPI1.setup({ mosi:B5, sck:B3, baud:1000000 });
=undefined
SPI1.send(0b00000,C0);
=255///
The device should send back a 32 bit number.
From my understanding reading the datasheet once the cs goes low the chip should start writing data to the espruino as the sck signal starts. Can anyone offer some pointers or explain the error in my understanding of SPI.
Thanks.
-
-
-
-
You could always poll the GSM board using the AT command for battery voltage.
at+cbc will return current state of battery charge.