baxter's Content - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

baxter's Content

There have been 63 items by baxter (Search limited from 30-March 23)


By content type

See this member's


Sort by                Order  

#58948 Spark Core (TI CC3000) Porting for Super WiFI Mini?

Posted by baxter on 29 June 2014 - 06:11 AM in Netduino Mini

Are you still working on your CC3000 Managed Driver? I noticed Jan 9 was the last commit on CodePlex. The 2nd generation CC3100 looks intersting. Maybe they have some of the CC3000 kinks worked out. I was going to buy a CC3200, but then changed my mind after recalling my experiences with the CC3000 Boost module and LaunchPad.

 

I purchased a Spark Core and it works pretty much as intended. It's easy to establish a local network connection, serve webpages and so on, but curiously, it won't respond to a ping. However, it will send pings and get responses. They blame this on firmware 1.29 which removed ping responses to fix an an ARP problem. Earlier firmware versions supposedly did have ping  response. In any event, I am reasonably happy with the Spark Core; I just wish it ran MF managed code.




#58961 Spark Core (TI CC3000) Porting for Super WiFI Mini?

Posted by baxter on 30 June 2014 - 05:34 PM in Netduino Mini

Yes, piwi ...




#58882 Windows on Devices? When?

Posted by baxter on 25 June 2014 - 01:07 AM in General Discussion

Hi All,

 

just registered on the windowsondevices web site, replied to their confirming email and some seconds later they replied again:

 

Quote: "Thank you for signing up for the Windows Developer Program for IoT.  We’ll let you know when your kit has shipped."

 

So appearantly something has changed ....

 

Cheers,

 

Me.

Got the same message ...

Interesting that they ask if using Spark IO (Spark Core) as a development board. I bought one and it does WiFi quite well. It has the  same footprint as the Mini; just a bit longer.




#60021 Getting started with Netduino Mini (early instructions)

Posted by baxter on 07 September 2014 - 06:21 PM in Netduino Mini

I would try to update your firmware. Select the TTL zip file since you haxe a TTL cable.
http://forums.netdui...-v420-update-1/




#60035 Getting started with Netduino Mini (early instructions)

Posted by baxter on 08 September 2014 - 01:50 AM in Netduino Mini

Did you first try to erase it by applying 5V to the gold ERASE pad? It's located at the top on the right hand side.
Flashing instructions after erasing are here toward the bottom of the page,
http://forums.netdui...-v420-update-1/




#59637 High Resolution Quad Encoder Problem

Posted by baxter on 09 August 2014 - 06:19 PM in General Discussion

I bought a couple of CY8CKIT-049-42xx for $4.00 ea,

http://www.cypress.com/?rID=92146

http://www.digikey.c...-42xx&x=14&y=16

I don't know if I will do any thing with PSoC, but the break-away USB-Serial Controllers will prove useful.




#59117 NETMF SerialPort and "BreakState"

Posted by baxter on 09 July 2014 - 05:42 AM in Netduino Plus 2 (and Netduino Plus 1)

Wrong cable ... The one you linked is USB to RS232. I should have been more explicit. What you want is is USB to TTL. Something like this,
(1) http://www.ebay.com/...e-/261101529602
or this,
(2) http://www.mouser.co...j627GFcejHp0Q==
or this,
(3) http://yourduino.com...ct_detail&p=164

 

With the first two, you can plug your jumper wires into the end of the cable and then into the breadboard to bring the signal lines to the breadboard for connections. The third style can plug directly into the breadboard, but be careful that the header pins have enough depth and are not too far offset from the edge of the PCB. Most of my USB to serial TTL are like number (3). The RS232 version you ordered is not of much use for Netduino work. I would cancel your order if you can. The RS232 cable can be used for download with the Netduino Mini.

 

Serial RS232 and TTL are different protocols that are characterized by the logic state voltage. If you measure voltage with no transmission on a TTL TX line, it will be 5V corresponding a logic 1. For RS232, logic 1 will measure at about 2.7V or less. In most cases, USB to RS232 adapters do not conform to the RS232 standard. A further characterization is; TTL idles high and RS232 low..

 

Comment on Fritzing layout
==========================
Last post: Remove the blue wire. Netduino RX doesn't have anything to do with the BREAK.
Next to last post: Correct, but lose the RS232 adapter. See above comments. If you use it, you will need to add add a chip to invert TX and RX from/to the adapter.

 

I will try to dredge up my lost knowledge of Fritzing and try my hand at layout of the breadboard. This is turning into an intriguing problem.




#59111 NETMF SerialPort and "BreakState"

Posted by baxter on 08 July 2014 - 10:05 PM in Netduino Plus 2 (and Netduino Plus 1)

Remove the red power to the diode.

 

I would step back to square zero on your project and then take small steps. First establish that you can communicate with the SRF01. Go to http://www.robot-ele...m/srf01tech.htm
and download the terminal program under heading, Testing (it compiles and runs just fine on my PC). Buy a FTDI based USB to serial adapter and plug it into your PC. The driver should install automatically; if it doesn't, then install the VCP drivers. Other chip based USB to serial adapters will work, but you may need to download drivers. Hookup the SRF01 as shown in the circuit under heading, Testing. You can get power from the adapter. The adapter and I/O to the SRF01 connections are: Diode cathode (band) connected to adapter TX, anode connected to SRF01 I/O and adapter RX. Just like your jpg picture hookup, but substitute the USB adapter connections in place of the Netduino connections. This should work because the PC serial class has a software BREAK. I would try it, but i do not have such a weird part as the SRF01. If you can't get a response then your SRF01 may be bad.

 

Now, you are ready to move on. I would port the code of the PC terminal program to run on Netduino. We know that the AND gate works for a BREAK so substitute the GPIO = low code here

 private void SendBreak()
        {
            SerPort.BreakState = true; 
            Thread.Sleep(2);
            SerPort.BreakState = false;
        }

I would also use the half-duplex circuit (call it Interface) then

Netduino RX(D0)   ---------------- RX (Interface) --- SRF01(I/O)
Netduino TX(D1)   --- AND gate --- TX(Interface)  --- SRF01(I/O)
Netduino GPIO(D4) --- AND gate 

The output of Interface is a single line connected to SRF01




#59149 NETMF SerialPort and "BreakState"

Posted by baxter on 10 July 2014 - 06:07 PM in Netduino Plus 2 (and Netduino Plus 1)

You are not going to be able to talk to the SRF01 from Netduino without the hardware break. I fired up Fritzing, made a schematic and connected the corresponding breadboard wires. The project is here,
https://www.dropbox....NXj2cVZn8bAJjYa

I am pretty sure it's correct, but no guarantees. Starting from a schematic, ratsnest wires are transfered back to the breadboard and you need to connect them up with wires. Fritzing is a work-in-progress and I find it very limited and cumbersome to use. I use Eagle Cad for all of my work.

 

In any case, you need to develop the capability to transfer a schematic to a breadboard. Here is a nice online free application for electronic design work,

http://easyeda.com/




#59163 NETMF SerialPort and "BreakState"

Posted by baxter on 11 July 2014 - 09:01 AM in Netduino Plus 2 (and Netduino Plus 1)

Well I really can't  make out any thing out from your photo. I haven't tested the half-duplex circuit, but it may have problems operating at 3.3V due to the forward voltage drop through the diode and also the resistor value may need to be adjusted. I am pretty certain he designed the circuit for Arduino which has 5V I/O. I suggest you breadboard just the half-duplex circuit. You can then statically test it with your meter. Instantiate COM1 on Netduino and let it idle. You should measure 3.3V on TX and RX. Next, Connect TX and RX of Netduino to TX and RX of the interface circuit.

 

(1) Measure the interface TX/RX; it should be greater than 2.7V.
(2) Apply 0V(GND) to TX/RX. Measure RX; it should be less than 0.5V (0 to 0.5V)
(3) Apply 3.3V to TX/RX. Measure RX; it should be greater than 2.7V.
(4) Disconnect Netduino TX from TX interface. Apply 0V(GND) to TX interface. Measure TX/RX; it should be less than 0.5V (0 to 0.5V)

 

If your measurements do not conform to (1)-(4), then the circuit will not work with 3.3V. The TX line from Netduino will probably need to be level shifted to 5V before connection to the TX interface or the circuit modified.

 

I am more than happy to help you, but if you are just starting out, I would suggest buying a book such as this,
http://www.amazon.co...t/dp/0596153740
This is a very lucid starter book. You don't want to farm your project out to a consultant. Stick with it and you will learn a lot. This is a conceptually simple project; all you are trying to do is talk over a serial line. As I said before, the first step is to get the SRF01 working from your PC with the USB to serial adapter according to the web page instructions.

 

More on logic signal voltage levels:
http://www.allaboutc.../chpt_3/10.html




#59180 NETMF SerialPort and "BreakState"

Posted by baxter on 12 July 2014 - 09:54 PM in Netduino Plus 2 (and Netduino Plus 1)

Success is sweet after a round of failures ...

 

My measurements with a BAT42 diode:

(1) Measure the interface TX/RX; it should be greater than 2.7V. ---> 3.0V
(2) Apply 0V(GND) to TX/RX. Measure RX; it should be less than 0.5V (0 to 0.5V) ---> 0.05V
(3) Apply 3.3V to TX/RX. Measure RX; it should be greater than 2.7V. ---> 2.9V
(4) Disconnect Netduino TX from TX interface. Apply 0V(GND) to TX interface.
     Measure TX/RX; it should be less than 0.5V (0 to 0.5V) ---> 0.03V

There is not a lot of margin on the high side when working with 3.3V, but enough.

 

Here is a Netduino VB 2010 simple serial text terminal I wrote to interact with something connected to the COM port. It's nothing fancy, but it works
https://www.dropbox....al Terminal.zip
You can translate it to C# with one of the online translators,
http://www.developer...t/vb-to-csharp/

 

You might consider the HC-SR04. It will probably be easier to work with than the SRF01 (no Break and no COM port, just an echo line)
https://www.dropbox..../HC-SR04_V1.zip
I translated the original C# to VB. The original link is in the program. I added some smoothing and statistics on the measurements.

 

I am glad that you are finally getting some hardware interaction. If nothing seems to work, it can lead to mountain of frustration.




#59092 NETMF SerialPort and "BreakState"

Posted by baxter on 08 July 2014 - 02:49 AM in Netduino Plus 2 (and Netduino Plus 1)

Arduino SoftSerial has the capability to setup serial pins (TX,Rx) or (TX,TX) for half-duplex as I remember. Looking at that diode circuit again. I don't think it will work. Their C# demo program is running on a PC with a software BREAK available and maybe the diode hooked up as shown is required by the program. This is what I don't understand; Quote: "A small schottky diode is used to prevent the SRF01 trying to drive the S22/S27's output line (data from the PC)."  If this is true, it looks like they have the diode connected backwards. 

 

Here is a circuit for a single pin software UART,

http://nerdralph.blo...tware-uart.html
and the driver,
https://sites.google...asicSerial3.zip

 

From the web page analysis of the circuit (Read SRF01 for AVR), it looks like this should work. Make connections:
(1) Tx/Rx is the connection to the SRF01 I/O
(2) TX = Netduino TX
(3) RX = Netduino RX

So, in addition to your BAT85 purchase, buy a 2N3904 NPN transistor and a 10K resistor. You can then experiment with both circuits. It is quite possible that there is a property or setting lurking somewhere in the MF serial class to put the serial port into half-duplex mode. I haven't found it. In any case, you are doing useful work here.

 

P.S.

 a ) Does one leg of the diode need to connect to D0 and the other to D1 (i.e. RX/TX)?

 b ) How does the RX line of the sensor connect to the diode if both legs are already plugged in?

===

Bring D0/D1 out to a breadboard with jumper wires and build your circuit there. Diode connected between D0 and D1 on the breadboard then connect a  jumper wire between the anode junction and the SRF01 input.




#59078 NETMF SerialPort and "BreakState"

Posted by baxter on 07 July 2014 - 04:48 PM in Netduino Plus 2 (and Netduino Plus 1)

I searched for the SRF01,
http://www.robot-ele...m/srf01tech.htm
you have not picked an easy part to start your hardware adventures. The problem is you are sending out on Netduino TX to SRF01 RX and SRF01 is sending back on the same line, but you are listening on the Netduino RX which has no connection to the SRF01. Hook Netduino TX/RX with the diode as shown in this circuit from the reference and it will probably work. The site looks to be pretty complete for interfacing the SRF01.

Attached Thumbnails

  • TX_RX Interface.JPG



#59009 NETMF SerialPort and "BreakState"

Posted by baxter on 04 July 2014 - 08:22 PM in Netduino Plus 2 (and Netduino Plus 1)

Frankly, I do not know if you can mess with the serial port parameters after you have instantiated it. Others may know. Re-reading the hardware on the TX line posts, I find the AND gate very appealing in its simplicity.

 

If I were trying to do this I would use the AND gate and;
(1) setup the serial port (COM1/D0,D1)
(2) configure a GPIO port as as an output port (say, D3)
(3) connect the GPIO port to input 2 of the AND gate , TX to input 1 and output to sensor RX
(4) in your sensor driver, include a BREAK command (default GPIO pin = high, must always be high outside of  BREAK)
(5) in the BREAK command code,
    ( a ) set the GPIO output port low
    ( b ) send text to the sensor equivalent to the required BREAK time
    ( c ) set the GPIO output port high
    ( d ) exit break command

5.b will send zeros in place of the text character. You need to workout the number of characters to send.

 

AND gate parts:
1 gate AND: 74LVC1G08
4 gate AND: 74HC08




#58974 NETMF SerialPort and "BreakState"

Posted by baxter on 02 July 2014 - 07:08 AM in Netduino Plus 2 (and Netduino Plus 1)

Notes collected on various forums for sending a break. It seems as though changing the UART to 1/2 or 1/4 of the actual line speed and then sending a single null byte will simulate a break. Sending breaks was in my  distant past and I really never tested break sending.

 

NOTES (sorry no attribution available)

===========================

 

(1)---------------
A serial break is not a character. It is a signal that can be sent using the
TX line of the device sending the break.

When a serial port is idle and no data is being sent the TX line is in a
logical 1 state. While data is being send the TX line rapidly transitions
between logical 0 and logical 1. Each frame of data takes a certain period of
time to send, depending on the bit rate of the connection. This is called
the "frame time" or "word time".

A break occurs when the TX line is held to a logical 0 for longer than one frame time.
------------------ End (1)

 

(2)--------------- Microsoft (PC)
Method 1
The International Consultative Committee for Telephone and Telegraph (CCITT) modem
recommendations require a break signal to be at least "2m+3" bits long, where "m"
is the nominal number of bit times in an asynchronous character, usually 10; this
means that the minimum break time is 23 bits, with no maximum specified. Usually,
much more than the minimum is sent, such as 100 or 200 milliseconds
(that is, hundreds of bit times at high data rates). The timer resolution in a PC
is sufficient for sending such "long" BREAK signals, but not sufficient to send
exactly 23 bit times.

 

Method 2
An alternative means of sending a BREAK signal of shorter duration is to temporarily
change the data rate in the UART to half or 1/4 of the actual line speed and then send
a single NULL byte. This is more precise than using SetCommBreak() and ClearCommBreak(),
but it has the disadvantage of corrupting received data during the time the BREAK
signal is being sent (because the received data rate is wrong during that time).
An application can change the date rate in the UART with a call to SetCommState().
The DCB structure passed to SetCommState() specifies the new data rate.
------------------ End (2)

 

(3)---------------DS2480B
If break is not available on the host UART then switching to
a slower baud rate and sending a zero byte can simulate a break. Switching to
space parity or changing to a 9-bit word length with a zero in the most
significant bit can also simulate a break.
------------------ End (3)

 

(4)---------------
If sending, you need to disable the TX function of the USART, set the pin as
an output and hold it low for the break period, then re-enable the TX function,
and you can start sending data.

If receiving you don't have to do anything too special... A break will come as a
received character with a framing error, and a value of 0x00.
------------------ End (4)

 

(5)---------------
You can change uart's baudrate to lower value and send 0x00 byte.
(e.g. 0x00 byte transmitted with baud=57600 is break condition for baud=115200)
------------------ End (5)




#59016 NETMF SerialPort and "BreakState"

Posted by baxter on 05 July 2014 - 04:57 AM in Netduino Plus 2 (and Netduino Plus 1)

Pin designations A and B are inputs and Y is output. The gates are grouped by 3 (A,B,Y) moving down from pin 1. You want 1A (pin 1) connected to TX and 1B (pin 2) connected to BREAK (or conversly, it doesn't matter). 1Y (pin 3) is the output of the gate connected to sensor RX. You need to move the white wire to 1Y (pin 3) next to the blue wire. Everything else looks ok.

 

I hope this works. It is a neat solution for a break thanks to Dave Tweed's answer on electronics.stackexchange.




#59002 NETMF SerialPort and "BreakState"

Posted by baxter on 04 July 2014 - 06:45 AM in Netduino Plus 2 (and Netduino Plus 1)

I forgot to include two references to do a break with some hardware on the TX line,

http://electronics.s...emitter-followe
http://electronics.s...me-periods?lq=1

 

As noted in the comments/answers, the circuits need improvement, but they allow control of your break with a GPIO pin. The AND gate suggestion of the of the answer in link 1 looks to be the best and simplest approach,
Quote:
"What you really want is an ordinary AND gate. When both inputs are high, the output is high, but if either input goes low, then the output goes low"

 

So,
gate input 1: TX, input 2: GPIO = high ---> gate out: TX = regular transmission
gate input 1: TX, input 2: GPIO = low  ---> gate out: TX = low/break (hold GPIO low for break time)

 

I don't know if this gives a genuine break, but it is worth a try.




#59027 NETMF SerialPort and "BreakState"

Posted by baxter on 05 July 2014 - 05:55 PM in Netduino Plus 2 (and Netduino Plus 1)

Your connections are now correct ...




#59031 NETMF SerialPort and "BreakState"

Posted by baxter on 06 July 2014 - 04:25 AM in Netduino Plus 2 (and Netduino Plus 1)

Here is a Netduino post that might interest you,
http://forums.netdui...mx-transmitter/
He is using the AND gate approach for the BREAK. Apparently it works because he has tested it.

 

Completely missed this reference ...




#58954 How do I connect Netduino+ to a pc wireless?

Posted by baxter on 30 June 2014 - 05:44 AM in Netduino Plus 2 (and Netduino Plus 1)

rickggaribay, sorry for the problems. Networking can be frustrating at times. I googled for the Vonets and it seems that there are problems in setting it up. The fact that it needs software for setup and is using WinPCap means that this is totally different from the Edimax approach which requires no installation software.

 

I just hooked up an Edimax that is established on my network with an IP address of 192.168.0.4 to a Netduino Plus 2 that is not running any network related code. I then went to MFdeploy and set the Plus 2 network parameters:
Static IP address: 192.168.0.50
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.0.1
MAC Address: 5c-86-4a-00-50-0f
DNS Primary Address: 8.8.8.8
DNS Primary Address: 8.8.4.4
DHCP: unchecked

The router has a DHCP range of 100-200. I then opened a command prompt and pinged 192.168.0.50 followed by arp -a with the result:

Pinging 192.168.0.50 with 32 bytes of data:
Reply from 192.168.0.50: bytes=32 time=45ms TTL=255
Reply from 192.168.0.50: bytes=32 time=2ms TTL=255
Reply from 192.168.0.50: bytes=32 time=2ms TTL=255
Reply from 192.168.0.50: bytes=32 time=2ms TTL=255

Ping statistics for 192.168.0.50:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 45ms, Average = 12ms

C:\Users\beb\Desktop>arp -a

Interface: 192.168.0.175 --- 0xb <--- desktop PC hardwired ethernet
  Internet Address      Physical Address      Type
  192.168.0.1           98-fc-11-6e-6a-40     dynamic
  192.168.0.4           80-1f-02-19-25-98     dynamic <--- Edimax
  192.168.0.50          80-1f-02-19-25-98     dynamic <--- Netduino Plus 2
  192.168.0.104         98-4b-e1-55-78-d6     dynamic
  192.168.0.113         80-1f-02-9d-b4-ec     dynamic
  192.168.0.117         f4-ce-46-4d-22-bc     dynamic

Notice the physical (MAC) address of the Netduino; it has now taken the MAC of the Edimax. I have no idea how this happens. But I think that the effect is that when you address the Netduino by its IP, it is actually being resolved to the Edimax which passes the traffic through to the Netduino. Although not certain, I believe that all of these ethernet to wireless adapters work the same way. I would suggest that you re-setup your Netduino network parameters with MFdeploy and make certain you are on the same subnet of your network. When I was searching for Vonets, I did notice that the latest software was important to get the adapter working.




#59283 How do I connect Netduino+ to a pc wireless?

Posted by baxter on 17 July 2014 - 05:34 PM in Netduino Plus 2 (and Netduino Plus 1)

I really think the key to getting these pocket routers to work is to assign fixed, but different IP addresses (outside of the main router DHCP range) and disable DHCP on both. The other important ingredient is to let the Edimax establish itself on the network before connecting the Netduino. Ping it and make certain it is in the ARP table. I also find that it works equally well with a network configured Plus 1 or Plus 2.




#58787 Sound Sensor, Wifi Shield and BreadBoard

Posted by baxter on 19 June 2014 - 06:51 PM in Netduino Plus 2 (and Netduino Plus 1)

I don't think there any Netduino specific WiFi shields. Look for an Arduino shield. Here is one,
https://www.sparkfun.com/products/9954
The problem with these shields is that the drivers are Arduino specific. This is a Netduino project using an Arduino shield with Netduino drivers,
http://forums.netdui...rary/#entry7870
But, expect to be frustrated with these shields because you need to talk to them over SPI. However, You don't need a WiFi shield. The Edimax simply turns your Netduino ethernet port transparently into a wireless connection; thereby avoiding all driver complications. After you configure the Edimax for your network, connect its ethernet port into the Netduino ethernet port, provide power to the Edimax and the Netduino will be connected to your wireless network. Also, another advantage is that you do not tie up any SPI pins.

 

If you want a stack arrangement,, just get a protoshield and affix the Edimax to it. The Edimax will fit exactly between the headers without any modification.




#58765 Sound Sensor, Wifi Shield and BreadBoard

Posted by baxter on 18 June 2014 - 05:55 PM in Netduino Plus 2 (and Netduino Plus 1)

Google is your friend,
http://www.newegg.co...N82E16833315095
http://www.ebay.com/...cat=0&_from=R40

You can buy breadboards anywhere; Mouser, Adafruit ...




#61779 12 water flow sensors 160ft away from N+2

Posted by baxter on 05 March 2015 - 07:32 AM in Netduino Plus 2 (and Netduino Plus 1)

The ESP8266 WiFi modules might be a nice fit for your project.  When using the nodeMCU Lua firmware they basically become programmable wireless access points. The ESP-01 costs about $3 and exposes 2 GPIOs. The modules operate as a TCP client or server or both. Out of the box firmware uses an AT command set, but the Lua firmware offers much more and is very stable. They require about 240 ma when talking on the network and 70 ma when not. They are also 3.3V and not 5V tolerant. The disadvantage is that one needs to learn a bit of Lua, but there are plenty of examples in the nodeMCU forum link below.

 

GPIO2 supports an interrupt to count pulses for your sensor and the latest version of Lua has floating point math so you could directly compute the flow rate on each ESP module. Each ESP module also has its own MAC address and a chipID for identification, accessable via Lua functions. There is also a Lua repeatable timer alarm  with a callback function. This is where you could do your calculations and send the flow rate with an ID every X seconds via TCP or UDP.

 

The range in open air has been reported as 366 meters with the PCB antenna. This, however, is optimistic in the real world. I have an ASUS RT-n66U router and about 40 feet away from it, through 2 walls and a floor, a laptop shows 5 bars for the network SSID. For an ESP under the same conditions, the ESP broadcast SSID shows 2 bars signal strength. Given your longer distances, you might need to add a wireless extender to the mix.

 

If you use them behind a wireless router, each of the modules can obtain an IPaddress with with Lua code like the following: (Lua has a file system and a file is executed with dofile("myfile.lua")


-- File name: init.lua
print("set up wifi mode") 
--this is sent back to serial terminal if connected, otherwise does nothing
wifi.setmode(wifi.STATIONAP)
wifi.sta.config("ret13x","XXXXXXXXX")
 --here SSID and PassWord should be modified according your wireless router
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function() -- repeat function every 1000 ms
    if wifi.sta.getip()== nil then 
    	print("IP unavaiable, Waiting...") 
    else 
    	tmr.stop(1)
    	print("Config done, IP is "..wifi.sta.getip())
    	--dofile("yourfile.lua")
    end -- if
 end) -- function

The init code will run on a powercycle or soft restart. The dofile("yourfile.lua") above will run once an IPaddress has been obtained and this is where you could put your flowmeter stuff.

 

here are some links,

 

ebay seller (USA fast shipping)

http://www.ebay.com/...html?rmvSB=true

 

nodeMCU forum:
http://www.esp8266.c...wforum.php?f=17

 

nodeMCU firmware(see pre_build) :
https://github.com/n...odemcu-firmware

 

API instruction set:

https://github.com/n.../nodemcu_api_en

 

For development, I use LuaLoader and a PC console TCP client for testing networking:
http://benlo.com/esp....html#LuaLoader




#59981 Safe code to convert byte[4] to float

Posted by baxter on 04 September 2014 - 01:06 AM in General Discussion

Here is some VB code to go from an IEEE 754 single to 4 bytes and back to a single. It is indeed the hard way to do it. I wrote this before the "unsafe" bitconverter appeared on the scene, but now use the unsafe BC and have never had problems with it.

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
'Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Imports SecretLabs.NETMF.Hardware.Netduino
Imports System.IO
Imports System.Text
Imports System.Collections
Imports System.Diagnostics
Imports System.Text.RegularExpressions
Imports System.Math

Module Module1

    Sub Main()  
        Dim buf() As Byte
        Dim sing As Single
        Dim svalue As Single = 44411.5625
        buf = SingleToFourByte(svalue)
        sing = FourByteToSingle(buf)
        Debug.Print("value - sing = " & (svalue - sing).ToString) '--> 0
    End Sub
End Module

    Public Function FourByteToSingle(ByVal ByteArray() As Byte) As Single

        Dim bin As String = String.Empty
        Dim denormalized As Boolean = False
        Dim exp, start, coeff As Integer
        Dim mantissa As String
        Dim sum As Double
        Dim TwoPow As Integer = 1
        Dim mult As Double = 1

        'Convert 4 byte array to binary in reverse order 
        '(assumes  given array came from a 32bit little-endian integer)
        '--------------------------------------------------------------
        For i As Integer = ByteArray.Length - 1 To 0 Step -1
            bin &= IntToBin(ByteArray(i))
        Next

        'Split apart the binary string. Assumes IEEE 754 single format
        '-------------------------------------------------------------
        Dim sign As Integer = If(bin.Chars(0) = "1", -1, 1) 'leading bit
        Dim expt As Integer = CInt(BinToInt(bin.Substring(1, 8))) 'biased exponent
        Dim fraction As String = bin.Substring(9)           'fractional part
        Dim TempFraction As Integer = CInt(BinToInt(fraction))    'integer for testing

        'Test for special cases (zero, denormalized, +/-infinity, NaN)
        'a good reference for thes cases: http://steve.hollasch.net/cgindex/coding/ieeefloat.html
        '----------------------------------------------------------------------------------------
        If (expt = 0 And TempFraction = 0) Then Return 0
        If (expt = 0 And TempFraction <> 0) Then denormalized = True
        If (expt = 255 And TempFraction = 0) Then Return CSng(If(sign = 1, 1 / 0, -1 / 0))
        If (expt = 255 And TempFraction <> 0) Then Return 0 / 0

        If (denormalized) Then
            exp = -126
            mantissa = fraction
            start = 0
            sum = 0
        Else
            exp = expt - 127
            mantissa = "1" & fraction
            start = 1
            sum = 1 'implied bit
        End If

        'Convert mantissa to single using double arithmetic to keep full precision
        '-------------------------------------------------------------------------
        For i As Integer = start To mantissa.Length - 1
            TwoPow = 2 * TwoPow
            coeff = If(mantissa.Chars(i) = "0", 0, 1)
            If (coeff = 0) Then Continue For
            sum = sum + 1.0 / TwoPow
        Next

        'scale the power of 2: 2^exp --> [(2^exp)*(10^-pow10)]*(10^pow10)
        '----------------------------------------------------------------
        'Constant to scale away exponent power of 2
        'log(2)/log(10) = 0.30102999566398119521373889472449
        'reqd power of 10 = (power of 2)*(log(2)/log(10))
        Dim ReqPowerOf10Const As Double = 0.3010299956639812

        Dim Pow10 As Integer = CInt(exp * ReqPowerOf10Const)
        Dim Pow2 As Integer = exp - Pow10 'reduce the power of 2 exponent [10^pow10 = (2^pow10)*(5^pow10)]
        mult = (2 ^ Pow2 / 5 ^ Pow10) * 10 ^ Pow10

        Return CSng(sign * sum * mult)
    End Function

    Public Function SingleToFourByte(ByVal singl As Single) As Byte()
        Dim byts(3) As Byte
        Dim test As UInt32 = CUInt(singl)
        Dim SingnOf As Integer = Sign(singl)                ' = -1 if negative
        Dim FracPart As Single
        Dim IntPart As UInt32 = CUInt(Floor(Abs(singl)))    'integer part
        FracPart = CSng(Abs(singl) - CSng(IntPart))         ' fractional part
        Dim FracPartBin As String = String.Empty
        Dim IntPartBin As String = String.Empty
        FracPartBin = DecFracToBin(FracPart)
        IntPartBin = DecIntToBin(IntPart)

        'Normalize
        Dim BinExpt As Integer = IntPartBin.Length - 1  'Highest bit set -1
        Dim Exponent As UInteger = CUInt(BinExpt + 127) ' Biased exponent
        Dim BiasedExpt As String = DecIntToBin(Exponent)

        'Remove most significant bit
        IntPartBin = IntPartBin.TrimStart({"1"c})
        'concatenate the mantissa and pad to 23 bits if necesary
        Dim Mantissa As String = IntPartBin & FracPartBin
        Dim LenMant As Integer = Mantissa.Length
        Dim Pad As String = String.Empty
        Do Until (LenMant = 23)
            Mantissa = Mantissa & "0"
            LenMant = Mantissa.Length
        Loop
        Dim IEEE754 As String = If((SingnOf = -1), "1", "0") & BiasedExpt & Mantissa
        Dim LenIEEE As Integer = IEEE754.Length
        Utility.InsertValueIntoArray(byts, 0, 4, BinToInt(IEEE754))
        Dim k As Integer
        Dim substr As String = String.Empty

        Return byts

    End Function

Function IntToBin(ByVal byt As Byte) As String
        'Convert a byte to a binary string 
        Dim temp As Byte = byt
        Dim binval As String = String.Empty
        Dim count As Integer = 0
        Do
            binval = CStr(temp Mod 2) & binval
            temp = CByte(temp \ 2)
            count += 1
        Loop Until count = 8 'pad leading zeros

        Return binval

    End Function

Public Function BinToInt(bin As String) As UInteger
        'Horner's method to evaluate polynomial
        '01110110 msb, msb-1, ... 0 (e.g. msb to lsb, left to right)
        Dim len As Integer = bin.Length
        Dim temp As UInteger = CUInt(If(bin.Chars(0) = "0", 0, 1))
        For i As Integer = 1 To len - 1
            temp = CUInt(temp * 2 + If(bin.Chars(i) = "0", 0, 1))
        Next
        Return temp
    End Function

Public Function DecFracToBin(frac As Single) As String
        Dim BinFrac As String = String.Empty
        Dim temp As Single
        Dim carry As Integer
        While frac <> 0
            temp = frac * 2
            carry = CInt(Floor(temp))
            BinFrac = CStr(carry) & BinFrac
            frac = temp - carry
        End While
        Return BinFrac
    End Function

    Function DecIntToBin(ByVal Intgr As UInteger) As String
 
        Dim temp As UInteger = Intgr
        Dim binval As String = String.Empty
        Dim count As Integer = 0
        Do
            binval = CStr(temp Mod 2) & binval
            temp = CUInt(temp \ 2)
            count += 1
        Loop Until (temp = 0)

        Return binval

    End Function





home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.