- ByPic Language Guide and documentation
- Very Quick Start
- Getting Started
- Method 1
- Method 2
- In Use
- Starting from Scratch
- Developing (simple web server)
- Comments and Errors
- Purchase <Byvac Shop> <eBay shop>
The BV503 is a programmable WiFi Link. This means that the user will have access to WiFi and be able to program GPIO (General Purpose Input / Output) over that link. This clears the way for browser applications or (apps) that can be used from anywhere network access is available.
Because the BV503 is essentially a microcontroller and not a Linux device, it is designed for GPIO work with all of the features of a microcontroller such as SPI, I2C, ADC, PWM, timers capture etc.
The microcontroller has a pre-loaded rapid application redevelopment system “ByPic” that enables easy programming just using text files, no programmer is needed. It can also be programmed / re-programmed in situ.
- Zip file containing programs and utilities (updated 4 Apr 2014 ** needs v2.08-29 see)
- Zip file version 3 - incorporates web server_f and LCD support
- SD Card contents - Quick start
- Download and unzip SD Card contents to the top level of an SD Card
- Put the SD Card in the BV503
- Switch on or press the reset button
- Set the wifi link on your smart device to BV503 and let it obtain an IP address
- Open a browser and type http://192.168.16.220:8000
- This will then attach to the BV503 web server.
There are several methods of use and ways to configure this device for use. In all cases an SD card is required that is readable by a Windows system, i.e. FAT16 or FAT32 file system. It does not need to be blank, an old SD Card will do. The required files only take up a few k and so just about any SD Card will do.
Download the zip file and unzip the contents to the card such that he directory structure is as shown. There may be more or less files depending on the version.
The HLK-RM04 directory is not required, it contains information on the wi-fi module.
There are two methods described here, both will work and depends on how you want to use the device. Joining an existing network will allow access to the BV503 from any PC on that network. Using the BV503 as an access point will allow only those PC’s that have Wi-Fi and are connected to the access point.
<<<< IMPORTANT DO THIS FIRST >>>>
This may not be how the device is eventually used but it requires no setting up. There are so many variables that can be altered that will stop the Wi-Fi module working and so is a good place to start to get confidence in the way it works.
The BV503 has been tested before leaving the factory with this set up and so is working. This eliminates 50% of the potential connection problems the other 50% is with the device being used to connect. If it does not work then there is a problem with the understanding of setting up the Laptop, tablet or phone that is being used.
- Copy the files as in step 1 above on an SD card
- Inset the SD Card into the BV503
- Connect the antenna * The module has a built in antenna that will work within a limited (2m or so) range.
- Switch on and wait for the green LED on the Wi_Fi module, next to the connectors to steadily flash and that the Con led is illuminated.
- On first use you may need to reset after 1 minute then wait for LED again.
L2 indicates that the main1.bas program is running, Con (LED) indicates that the wi-fi module is connected to ByPic the web server will then be run. To test this, on a lap top, tablet or smart phone look for a wi-fi network called "bv503" and connect to it. It is open and so no password is needed.
The Wi-Fi module will issue a suitable IP address for the 192.168.16 network.
In a browser address bar type:
This will bring up the index page to operate any relays that may be connected.
If the web page is not found then make sure that you are still connected to BV503. Operating systems have the habit of re-connecting back to an existing WiFi connection so keep an eye on that.
Try also 192.168.16.220 (without the :8000) This should bring up the Wi-Fi management console. If this fails then disconnect the BV503 and re-connect. Don't forget to check if the laptop or tablet is still connected to BV503 after the BV503 boots up.
Check again that the URL in the browser address bar is 192.168.16.220:8000
*** Do not progress any further if the above doesn't work as we know that at this point the BV503 is working but the Laptop, tablet or phone isn't connecting properly. This will be down to a simple mistake in the settings. Get this going first, if you progress onto modifying the default.cfg file as described in method 2 and it doesn't work it will be very difficult to diagnose the error ***
Managing Through a Socket
Access to the ByPic can also be obtained via a socket. For this you will need the free BvSerial terminal emulator. This is free and forms part of the ByPic IDE, the IDE is here but to learn more about how ByPic works and how to download other software easily then start here.
Make sure that the serial jumpers are in place at 
Of course the lap top or host device should be connected to the 192.168.16 network !!
The web server will be running to stop it simply press enter to break out of the web server loop.
Shown is the command to illuminate LED.
** Make sure method 1 is working before trying this **
This is where there is already a known Wi-Fi network, by known you will need the SSID, security type and password of the Wi-Fi hub and also the IP address of the network.
This set up is a bit more difficult as all the variables need to be set in order for communication to take place.
- Discover your network address. See Discovering your network for how to do this
- Delete the existing 'default.cfg', this was from the the 'ap_cfg' directory and copy the 'default.cfg' from the join_config directory to 'default.cfg' at top level.
- Edit the new default.cfg file on the SD Card and set the IP address, e.g.
Put your own IP address here, put the router or gateway address here
Set the wifi parameters, if the SSID:
wifi_conf=BTHomeHub-22AA,wep,02abcd1f15 (example, put your own information in)
In the above, the SSID is first, followed by the security type, followed by the password. Check in the default.cfg for the security types that are allowed. These parameters should exactly match those of the network you will be connecting to
- Place the card in the bv503 and press the reset button [15(R)] or cycle the power.
The BV503 will initially configure the Wi-Fi module and attempt to connect to the existing network. After 30 seconds the green LED on the Wi-Fi module will be flashing steadily and the Con led illuminated.
Assuming the net_ip address is 192.168.1.220 then open a browser and in the address bar type:
Normally browsers work with port 80 by default so most browsing is done without specifying a port. In this case the port is 8000 and so it needs to be specified as above.
All being well an index page will be shown.
If the :8000 is left off then HKL management page will be shown.
You will also be able to connect directly to the ByPic operating system via a socket the same way as described in method 1
Somtimes the wi-fi module can be annoyingly hard to get going but once it does connect it is very reliable providing there is a good signal. If there is no response then wait at least 30 seconds (until the wi-fi module green light if flashing steadily) then power cycle. Do this at least twice then have a look at the trouble shooting guide.
Several programming checks can are made at start up and this is explained in the text here.
The options for the BV503 are considerable and this will be up to the user how the module is used. In a nutshell the ByPic can run programs that will communicate using UART1 (TX/RX 1 on the Wi-Fi module). This can be accessed via a socket and so for example a web server can run on ByPic, serve up pages and react (turn things on/off, get analogue data) to those pages. That is just one example. There is also another interface that can communicate directly to the ByPic so that it can be re-programmed via the network.
Access to the web can be implemented in many ways, this description is just one way of implementing a simple web server. The goal of course is to ultimately control the ByPic.
Provided on the resource zip file is a simple web server and on the example implementations, the web server is invokes as a continuous loop. The loop can be broken by any byte coming in via UART 2.
The server needs to be listening all of the time, this can be accomplished by a simple loop. The buffer implemented on UART 1 will cache up to 800 bytes and so this will accommodate a simple page. Any data that comes in on the correct IP address and port (known as a socket) will be passed onto UART 1. ByPic can then interpret this data.
A web browser request is a specific sequence of text that can be interpreted by ByPic, this is something like "GET /<page or action requested> HTTP/1.1" The web server will process the page before sending it back. There are two distinct operations needed, output and input.
A full explanation of how the web server works is provided on the Bypic website here The index page will take you to the BV503 specific pages.
It is possible to access external sites as well providing that the router that the Wi-Fi module is connected to is connected of course to the internet. The 'netutils.bas' file contains information on how to do this.
The technique is to change the mode from server to client, this can be done with the connectIP() function. There is a function that is called getDT() that will get the date and time. A connection is made as a client to Google and a header request is made to their web service. This in turn returns a head that contains the current date and time.
At some later date this could request data from a 'proper' time service but as most web servers, in their head contain the current date and time there seems little point.
Obtaining the IP address of a web site is more difficult. Currently the ping command of the Wi-Fi module is used as there does not appear to be a host or dig command onthe wi-fi module that would do the job. This can be problematic as sometimes an IPV6 address is returned and the current firmware of the Wi-Fi module cannot handle that.
The ByPic firmware can be upgraded form time to time and also you may want to change the way the ‘core’ files work. By default when the SD Card is inserted into the BV503, the core files are downloaded into the BV503 Flash, this effectively makes the BV503 ‘purposed’ for this job – Wi-Fi link making lots of functions available for this purpose.
The files are only downloaded once, if they exist already in the Flash they are not downloaded again so if a function is changed or a function added to say file netutils.bas then this will not be reflected simply be placing it on the SD Card. To get the functions into Flash, the easiest way is to clear the all of the Flash and the ‘main.bas’ will take care of downloading all of the files again into flash. Although there are quire a few this only takes a few seconds.
- Remove the SD Card
- type flclear(0)
- Optionally upgrade ByPic if there is a new version, check www.bypic.co.uk
- Put the new files onto the SD Card
- Insert the SD card and reset
NOTES: fclear(0) removes all of the saved function from flash (flclear(1) removes only the last saved set of functions). The new files can be written to the SD Card using Windows. When the card is inserted and reset, the files are automatically loaded again.
To understand what is happening; when ByPic starts it will look for a file on the SD Card called ‘main.bas’ The actual file is here: It will run the function called main().
(main0.bas is now loader.bas)
The function lookup() will return the address of the function of constant found in flash. If it returns 0 then it does not exist and so it is loaded into ram with flload() and then it is saved to flash with flsave(). By specifying a function or constant in flasve(), as above it will only save the functions or constants AFTER the one specified. Because this program ‘main.bas’ is also in ram ,we do not want to save this as well, hence specifying “STARTP” in flsave.
If you take a look inside startup.bas then the first item is a constant called “STARTUP” this is simply there so that main.bas can use it.
The file ‘main0.bas’ (now loader.bas) does exactly the same job
Development of software is a process of writing functions. The best way to so this is to have a USB to serial device connected to the U2 connector, however if a socket has been established then that can also be used.
A file is uploaded to RAM with the .tl command (BvSerial), functions can then be tested in ram before committing to flash. There is no requirement for functions to be committed to flash and can reside on the SD card if required. Main1.bas is an example of this, it is never saved to flash but simply runs from RAM.
For convenience there is also .upf (upload file) command that will transfer a file form the host to the SD Card, this will save having to physically remove the card from the BV503, also when used remotely files can be uploaded to the SD Card. (currently there is a bug in BvSerial that causes BvSerial to crash when used more than once, press enter between .upf to mitigate it)
By default the web server is running, simply press enter and this will break out of the web server loop, to run the web server again type 'dos'.
There is now a standard web server (currently webserver_e.bas) that has been developed so that ByPic functions can be defined inside a html file. This should work for most purposes with some limitations.
The full explanation is on this site
By defualt the server is already installed onto Flash and can be invoked by typing dos. The actual server is called http_server() and can be called in any program loop,or even using an interrupt.
while comkey?(2) = 0 // wait for full line if bpos(CPORT,0,"\r") > 0 then http_server() endif wait(100) wend
The above is the 'dos' loop; obviously other functions can be placed in the loop. Given the leisurley pace of a browser the http_server() only needs to be called every half second or so.
The server is reasonably complex and this arises from the fact that a web browser is not ideal for sending and receiving real world information and so must be manipulated into doing so. A browser is however on every conceivable IT device so it is well worth the effort.
For more interactive sessions then an 'app' would be more appropriate, all 'apps' can open a socket and talk via that which is much quicker. For windows this can be done using Python or VB and for a Phone I would recommend Basic for Android (B4A) or learning Java.
There is a great potential in this device and only the surface has been revealed with the code provided. Microcontrollers are excellent for:
Analogue to digital conversion
Setting and detecting digital values
Interrupts and input capture
To name a few. Excellent control can be provided by the microcontroller and user interface along with the power that is available that can be provided by the host. Setting up a complex template for example, e.g a green house controller can be adequately controlled with a microcontroller but entering the differing times, dates, on / off, heating requirements could be easily handled on a web browser and then downloaded as a set of numbers. This would otherwise require a clever design with lots of multi function buttons.
There is of course the opportunity to enter this information from say a tablet device that is not fixed to say the inside corner of the greenhouse.
The marriage between a microcontroller with its own operating system and the Wi-Fi module for wider communication is ideal in that the microcontroller is designed for GPIO and is easy to program for that purpose whereas the Wi-Fi gives access to much better user interfaces and the possibility of very remote control.
are you on the same network!!! only devices on the same network address can connect. For example:
192.168.11.any can connect to 192.168.11.any
192.168.16.any cannot connect to 192.168.11.any
** The first three digits MUST match **
When the Wi-Fi module is operating correctly the red LED should be on and steady, the green led next to that should be on and steady and the green LED furthest away from the red LED should be flashing slowly.
NOTE: The Wi-Fi module does run quite warm, that is normal.
This is the main serial connection to ByPic and ii is provided at  (see Green Path). If a Wi-Fi connection cannot be successfully established then this will give access to some useful functions that can be used for diagnosis. Any USB to serial interface will do. Connect TX on the USB to serial to RX on the connector and RX on the USB to serial to TX on the connector and also connect ground, so only three wires are required.
Use BvSerial and set to the given COM port (given by your operating system) and set the Baud rate to 115200 (.baud 115200) - BvSerial commands start with a dot. Pressing return should reveal a yellow ok, if not recycle the power and check the connections.
This is typically what to expect with the SD card removed. If the SD card is inserted and reset pressed the logging system will show you what's going on.
This is unusually perfect, there may be some errors on your system. Some functions that are useful and can be simply typed directly into ByPic:
init() use this from time to time, there is a bug that disconnects the com port, this will restore it.
prinfCfg("default.cfg") Shows the current configuration against the default.cfg file. This can be checked against the actual config file.
Mode(1) (note upper case M) this should return 1 or 4, if not use init(). In this mode commands to the Wi-Fi module can be entered e.g
The commands are in the HKL-RM04 data sheet, they are entered without the leading at+ as shown above.
connected() When the wi-fi has joined a network this will return 1
It is likely that most problems will be due to the wi-fi configuration. There are three ways of configuring the wi-fi module.
1) The normal configuration is via the ByPic program and a configuration file on the SD Card. This has the advantage that the configuration is checked against the actual configuration of the wi-fi module and only those parts that need updating will be updated. The file containing the updater is on bv503.cfg and is called at start up by main1.bas using this line 'updateCfg("default.cfg")'
2) The module can be configured through a browser, the address is the same as the configured address but the port is always 80. So for example if the address is 192.168.16.220, then just putting this address into a browser will bring up the configuration details.
3) It could be that for some reason no access is possible through a browser of from the ByPic system. In this case there is a third option. The light blue path and connector  as described in the hardware section will give direct access to the wi-fi module. Connect a USB to serial converter to this interface and use the config-tool on the zip file. The Baud rate for this is normally 115200. This will allow configuration of the wi-fi module without regard to any other hardware.
To make it easier to develop code and use for the first time. Some checks may have been left out of the main1.bas. This may have the effect that the wi-fi module may not initialise correctly and thus there will be no wi-fi connection to the external browser. For a 'final' working system this is not desirable and so there are checks that can be put in place to mitigate this.
// check that the module has booted up by trying to set mode. At first // switching this can take up to 30 seconds for j = 1 to 12 if Mode(1) <> 0 then break else syslog("main1",format$("Waiting for wi-fi module <%d>",j)) endif next
The module is much slower than ByPic and so the code above will wait until the module has booted up.
// check configuration against the default, if the defailt.cfg file has // changes then the wi-fi module will be updated if finfo("default.cfg",a$) = 0 then // it exists updateCfg("default.cfg") endif
It is a good idea to see if the config has been updated but only AFTER the module has booted.
// this is where the wi-fi modules connects to the infrastructure - or not // connect can take about 30 seconds if an update has taken place for j = 1 to 15 syslog("main1",format$("Waiting for wifi connect <%d>",j)) ledCon(1) if connected() = 1 then break endif wait(100) ledCon(0) next
The last thing to do is to check that the module is connected.
There are some errors that have been found and possibly not yet corrected. Thanks to everybody that has contributed.
"When using I2C, the built in pull up resistors, value 10k, are a bit too large for some slave devices, additional pull ups are needed"
** These have been changed to 5k6 on later versions
"The Relais8 of bank 1+2 cannot be controlled thru the browser because the code in the file "webinput.bas" is if (pin < 7) && (pin >= 0) then.....but it should be....if (pin <= 7) && (pin >= 0) then(it is hard to see but the difference is <7 vs. <=7)"
"In the file " join_config/default.cfg" the line "remoteip=192.168.1.230" has to match the net_ip from further above. Otherwise it does not work. In the default net_ip you defined the ...220 and in your examples you always talk about the...220. It is easy to miss the change of the remoteip from ...230 to 220. I think it would be a good idea to change it to ...220, too, and put in a little comment about matching the remoteip"