-
-
-
-
I am working on a project where I am using my Espruino board to monitor Serial1. With regular intervals there are a couple of bytes arriving. The message contains status information, and I have to take action depending on the status bits. The action can be to turn on some LEDs that show status and fault information.
I have figured out how to read the status bytes by converting them to decimal numbers, but I am struggling with how to detect if the communication suddenly stops. For example, the gadget that I am monitoring goes silent because there is a power interruption. How can you detect that there has been no communication for 3 seconds, for example? -
Ok, I figured out a way. There must be more elegant ways to do this, but at least now I can see what I am receiving and I can take some actions depending on the messages.
Serial1.setup(2400/*baud*/); Serial1.onData(function (e) { var tr=(e.data); p=tr.charCodeAt(0); print(p); switch (p) { case 80 : var s = "CV,1.6A to 3A"; print(s); break; case 96 : var s2 = "CV, < 1.6A"; print(s2); break; case 85 : break; default : var s3="*"; print(s3); } });
-
-
-
-
to find p-channel MOSFETs that operate with 2.5V on the gate you could look at this page
http://www.mouser.com/catalog/catalogusd/646/674.pdf and check out the part numbers that are listed with Rdson at 2.5V.
if you want to connect the p-ch MOSFET to +12V you will of course need a part that has high enough gate voltage rating. so you may choose one that has Rdson rated only at 10V and 4.5V, and 20V gate voltage max rating. some of the parts that need very low gate voltage also have very low maximum gate-source voltage rating, for example 8V maximum.
there are different ways you can drive a p-ch MOSFET connected to +12V from a logic signal with 3V amplitude. you could use a npn transistor with base connected thru a 10k resistor to 3V and the emitter to GPIO pin. the collector connects to the gate of the p-ch MOSFET. the source of the p-ch connects to +12V and you need a resistor (10k) between gate and source, to keep the p-ch off when he npn is off. -
I am afraid that trough hole parts are a thing of the past. they are only manufactured to be used in old designs, these days all components are surface mount. so it is really hard to find any MOSFETs in through hole package that can be controlled by 3V. That does not keep some companies from advertising for example TO-220 MOSFETs as suitable for 3.3V GPIO... out of ignorance or just to make a buck they point to the gate threshold voltage which is a pretty misleading figure. you need to look at the Rds(on) specification. if the device is only rated at 4.5V and 10V you probably only can use it at very low currents if at all, with 3V gate voltage.
It is quite easy to solder a SOT-23 device onto a piece of circuit board and add solid wires to make it possible to plug into a breadboard, if necessary. these days, SOT-23 is considered a quite old package type, and quite large compared to modern packages. for really high power, consider Power-SO8 type packages that have a large pad that is connected to the Drain. the large pad conducts heat into the circuit board. just don't forget to select a part that has ON-resistance specified at 2.5V. or use a MOSFET gate driver and power it from 5V or higher, then the sky is the limit when it comes to power handling ability. -
-
I did not actually time the Waveform capture, so I would need to repeat the test to know the actual capture rate. The AnalogRead spent 0.0196s to capture 100 samples.
Edit: I tried to repeat the Waveform capture and came up with different time values depending on how many data points I captured. at 200 points it seemed that the sample rate was around 42kHz, and if I increased the number of samples it seemed that the rate increased. However, I did not have the time to make real time measurements, I relied on getTime() readings before and after the capture. -
I was briefly looking into the analog sampling speed when working on a solar panel diagnostics circuit. With the STM32F4 Discovery board I managed to collect my 100 samples at 12 bit resolution with a sampling speed of 5kHz. I also tried the Waveform which gives 8 bit data, at 100kHz, and I am still scratching my head trying to see if I can use the 8 bit resolution for the type of measurement I am doing. it may be possible but I need to figure out how to process the data. In my case I can collect the data and process it afterwards, so the delays in Espruino is not a major issue. It would be nice to be able to increase the sampling speed at 12 bit resolution with a factor of 5 or more, that would open up other applications.
-
the 3.3V regulator is very tiny, and I would not connect a 12V battery and expect it to work. a look at the datasheet for the MIC5205 shows that the temperature rise is about 220 degrees per Watt. if the Espruino draws 35mA and we connect a battery with 15V then the dissipation is 0.41W which means that we may reach over temperature and the regulator shuts down. it is better to use a 5V USB charger of the type you plug into the cigarette lighter in your car, between your battery and the Espruino. this way you can add some additional load to the 3.3V (about 100mA I believe). or you can power your extra gadgets from 5V.
be aware of the danger when you connect a battery. the battery voltage can be above 15V and there is an inrush current at plug in because the capacitor at the input of the 3.3V regulator is quickly charged. there can be an overshoot in capacitor voltage because of the inductance in the battery leads (an LC resonant circuit is formed) and if the resistances are low, the capacitor voltage can theoretically double when you plug in the battery. this would kill the regulator.
if you are working with solar panel charging of the battery you should also be aware that the voltage from the panel will be as high as 24V when the battery is not present. -
Thank you! Very interesting, I have to try it out.
In my case I really need the 12 bits for measurement accuracy, and I need to capture two signals practically at the same time as they are related. Maybe I could multiplex the input so that I capture the two signals on the same pin but the 8 bits resolution is a bit harder to work around. I have to try it out. -
I modified my code according to your example and the time required to capture 2*70 readings with time stamp dropped from 35ms to 21ms. This is a significant improvement, but I am still interested in reducing the time required for this measurement. The function that I am working on is a simple maximum power point tracking for a solar panel powered charger where partial shade occurs frequently and rapidly. The faster I can capture the data, the more accurately the charger will track the maximum power point. This allows the charger to harvest more of the available energy from the panel.
function read() { var t=getTime(); var d = []; for (var i=samples; i>0; i--) d.push([getTime(),analogRead(C1),analogRead(C5)]); for (i in d) d[i][0]-=t; return d; } function send() { for (var k=0; k<samples; k++) { print (data[k]); } } var samples=70; var data= read(); send();
-
One of the functions that I need for my project is to capture two analog signals and time stamp, and at least 70 samples. I tried to use a Beaglebone Black and wrote a simple Python program. I then tried STM32F4 Discovery and wrote the same function using Espruino. I was pleasantly surprised to see that the sample rate was almost five times higher with this approach. It is almost fast enough for what I am doing, but it would be nice to get a factor of 10 improvement in sampling rate. Right now the measurement takes 35ms to complete, that is reading two analog signals and the time 70 times and saving it in an array for transfer to a PC later. If anyone has insight into how I can speed up my measurement, I am very interested to hear more. My little program is:
function capture() { digitalWrite(C0,0); setTimeout(read(),2000); send(); } function read() { tick1=getTime(); for (var i=0; i<samples*3; i=i+3) { data[i]=(getTime()-tick1); data[i+1]=(analogRead(C1)); data[i+2]=(analogRead(C5)); } } function send() { for (var k=0; k<samples*3; k=k+3) { print (data[k],data[k+1],data[k+2]); } } var samples=70; var data=new Float32Array(samples*3); capture();
-
-
> require("Encoder").connect(A1,A5,function (direction) { step += direction; if (step >=4) { pos += 1; if (pos>96) { pos=96; } step=0; print_pos(); } if (step <=-4) { pos += -1; if (pos<20) { pos=20; } step=0; print_pos(); } });
this is my workaround for getting one count per click (probably there is a more elegant way - I am new to javascript..)
the encoders I have are the cheapest kind, but used in this way it does not seem to be any difference if I have RC filters to handle debounce or not. good to know that debouncing will be introduced in the code later on. -
A related question is if the RotaryEncoder module has debounce? I noticed that for each click when I turn the knob I always get four pulses. fortunately that is easy to work around. I have not checked the waveforms from the mechanical encoders yet, but I am using two, and one with and one without RC filter for debouncing. Both give four counts per click. (Mecanical encoders have a lot of contact bounce and need to have hardware or software debouncing)
-
My interest in Espruino started as I was looking for an alternative to NETMF for programming STM32F4 micro controllers. I am a switch mode power converter guy and micro controllers are used in high power converters. I am not myself a programmer but I am convinced that by using a high level language the task of writing code for prototyping purpose will be much faster. I can do some basic programming.
A year ago I developed test equipment for my own use for solar powered applications using VB. net and NETMF on an STM32F4 Discovery board and was pleased to see how quickly I could write the code and how compact and manageable it was compared to the C language. But the development of NET Micro Framework seems to have stagnated, so I am not sure this is the right path to follow. Right now I am looking at Espruino as an alternative. I am working with solar powered MPPT chargers and other power converters. -
-
Thank you! I had connected a 4*20 serial LCD display to A0 (UART4TX) which also is labeled BTN1. After moving the wire to C6 (USART6TX) and changing Serial4 to Serial6 it works fine. I can now unplug the STM2F4 Discovery board and when I power it up from an external source or a computer it works as expected.
During my troubleshooting I first tried the suggestion to type load(); after powering up and found that the simple Rotaryencoder program would start working after I pressed Enter, so apparently the programs are saved after typing save(), but they would not load at power up if I had my display connected to A0 pin. I am using a simple level translator for the display communication, as it has a 5V controller. the level translator consists of an npn transistor with base connected to 3V through an 18k resistor, emitter to the Discovery TX pin and collector to the display RX pin, with anohter 18k pullup resistor to 5V of the Discovery. this will give 5V swing on the display signal while the Discovery pin only swings 3V. Just in case someone is interested in a simple level shifter. Another simple circuit that works is to use a small diode 1N4148 from RX to TX, still need the pullup to 5V on the display. This gives about 0.6V to 3.6V on the display RX pin which in most cases works, even if the worst case may require 4V for a high level. -
it appears that I can no longer save a program on my Discovery board. I can Send a program to the board and it starts to run and the program works, and I write save(); and when I press ENTER it seems that the program is being written, as I see the "Erasing Flash.. and Programming 109000 Bytes... Checking... Done!
and then it shows the
Running onInit()...
as expected, and my program still works. but if I unplug power and try to run the program with or without connection to a computer, there is nothing. the program does not appear to have been saved.
this used to work. I am using the latest web ide and the latest nigthly (1v51 it says).
I have not tried to go back to an earlier version. I wonder if I am doing something wrong, but my programs used to run standalone after being saved()
..the reason why I don't think it is a good idea to sell the board with pin headers soldered is that the pin headers take up a lot of space, especially when they are used. that is, wires with connectors are plugged in. many users would buy the board because is is very compact. but the connectors would really make it difficult to fit the board into a small space, compared to if you just solder the wires into holes. and soldered connections are a lot more reliable than pin headers and matching connectors. so I would definitely sell the board with pin headers but not soldered. it can be difficult to remove pin headers that are soldered.