Lucid Code Examples

I figured that instead of creating a blog entry of each little Lucid program I make I’ll keep uploading them to Github. They should be fairly easy to understand. I’ll make a blog entry for any complex programs I make that require a little explanation.

You can find them here:

Feel free to contact me if you have any questions 🙂


Binary Counter (updated)

Here’s a simple binary counter using the onboard LEDs on the Mojo V3:


Source code:

I found an even simpler code:


Source code:

ISE 14.7 + Mojo V3

I wanted to play with FPGAs so I bought a Mojo V3 board ( (FYI I got cheaper from another site). To use this board you need the Xilinx ISE software which is available for free. Xilinx provides two methods:
1) Download a pre built VM with the ISE software already installed
2) Download the install files and do it your self.

The obvious choice I thought would be option 1. I download the VM from here (

Here’s my quick review of the VM:

  • It uses Oracle Linux 6.4 running Kernel 2.6-32.358 which can’t interface with the Mojo
  • Despite my best efforts I couldn’t change enough settings to make it interface with the Mojo V3. Oracle Linux kept loading the Mojo as ttyUSB0 instead of ttyACM0, and I couldn’t change that.

After that experience I decided to build my own VM but this time use Ubuntu as the base system. I used Ubuntu 16.04 and everything worked beautifully!

IOT Smoke Alarm Notifier

I tried to follow this tutorial ( but it didn’t really work. It didn’t really explain everything but I think I understood it. In the end I got this error in LuaLoader:

Executing Interrupt Sensor Software
Listening for Sensor Inputs…
PANIC: unprotected error in call to Lua API (1a_interruptSensor.lua:39: ‘<eof>’ expected near ‘end’)

I didn’t like this Lua interface so I’m going to try something else.

Few things to note:

  • you can no longer download the lua firmware, it is now a custom build service from where you can specify which modules you want



If you’re making an WPF Visual Basic application and make a custom IValueConverter for the first time you’ll probably see this message

“The name <your_class> does not exist in the namespace “clr-namespace:<your_application>

Here’s a screenshot from the XAML Designer:temp1

The fix is surprisingly easy:

  1. Change that line to “<local:Application…”
  2. Build the solution
  3. Change it back to “<local:ID2Converter…”
  4. Voila!

In case you’re wondering, my xaml.vb file looks like this:

Imports System.Globalization

Public Class ID2Converter
 Implements IValueConverter

 Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert
 ' blah blah blah
 End Function

 Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
 ' blah blah blah
 End Function
End Class

Public Class MyClass
' blah blah blah
End Class

So, you can put the IValueConverter in the same xaml.vb as the class using it. No need to declare namespace etc 🙂

Arduino + DS1307 RTC

Another demo for interfacing an Arduino with the DS1307 Real Time Clock. The board I used (see here) also has an integrated 24C32 32K EEPROM which we won’t worry about in this demo.

Here’s a picture of my setup:


Materials Used:

  • Arduino Uno R3
  • 16×2 LCD Shield
  • DS1307 board (I used this one) but you could use this one too
  • CR2032 button cell

Wiring details:

(NOTE: If you’re using the same board as me then wire to the side of the board with the pins SQ, DS, SCL, SDA, VCC, GND & BAT)

  1. Uno’s 5V (via LCD Shield) to RTC’s 5V
  2. Uno’s GND (via LCD Shield) to RTC’s GND
  3. Uno’s Analog Pin 4 (via LCD Shield) to RTC’s SDA
  4. Uno’s Analog Pin 5 (via LCD Shield) to RTC’s SCL
  5. Leave the other pins unconnected
  6. Put the button cell in!

You can find the code here. And voila! 🙂

Arduino + HR-SR04 Ultrasonic

I wanted to try an Ultrasonic sensor so I bought the cheapest one I could find, the HR-SR04. I used this tutorial to learn about the ultrasonic. Basically I thought the Ultrasonic would provide an analog signal with the distance…well I was wrong. Distance is calculated based on the time taken for an echo signal to be sent and received.

Here’s a picture of my setup.


Materials used:

Wiring is easy:

  1. Uno’s 5V (via LCD Shield) to sensor’s 5V
  2. Uno’s GND (via LCD Shield) to sensor’s GND
  3. Uno’s Digital Pin 0 (via LCD Shield) to sensor’s ECHO
  4. Uno’s Digital Pin 1 (via LCD Shield) to sensor’s TRIG

You can find the code here. And voila! 🙂