Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Lego RCX Notes

I tested these steps under WSL with Ubuntu.

I no longer have an official LEGO IR Tower, but in 2014 I created one with a simple IR receiver and an IR LED. The Arduino firmware and Eagle files are here: Boards can be ordered from OSHPark here:

Big shout out goes to John Holbrook (@johnholbrook on GitHub, @whole_brook on Twitter) for his awesome, up to date article found here:

The following writeup (and my 2014 IR Tower hack) should provide a more complete answer to one of the FAQ's on that page ("Can I send data to the RCX from a [TV remote/IR port on an old laptop/IR LED and an Arduino]?").

I posted photos and more details to Twitter here:

Program stuff with ncq

Apparently, you can also get ncq from sudo apt install ncq but I didn't try that.

Compiling ncq from source

  1. Install the build tool chain and the dependencies:

sudo apt install build-essential bison flex

  1. Patch nqc/DirList.cpp to replace strlcpy() and strlcat() with strncpy() and strcat() respectively. Usage of sizeof() worked to at least compile bin/nqc. Here's the git diff showing the patched lines. (Note: I'm not sure this is the right way, but it should be close... I think???) I opened a GitHub issue for this here: If the author writes back accepting this approach, I'll open a PR with these changes.
diff --git a/nqc/DirList.cpp b/nqc/DirList.cpp
index 766b2b4..6bccc93 100644
--- a/nqc/DirList.cpp
+++ b/nqc/DirList.cpp
@@ -53,7 +53,7 @@ bool DirList::Find(const char *filename, char *pathname)
     struct stat stat_buf;

     size_t len = sizeof(pathname);
-    if (strlcpy(pathname, filename, len) >= len) {
+    if (sizeof(strncpy(pathname, filename, len)) >= len) {
         return false;

@@ -61,8 +61,8 @@ bool DirList::Find(const char *filename, char *pathname)
         return true;

     for(Entry *e = fEntries.GetHead(); e; e=e->GetNext()) {
-        if (strlcpy(pathname, e->GetPath(), len) < len) {
-            if (strlcat(pathname, filename, len) < len) {
+        if (sizeof(strncpy(pathname, e->GetPath(), len)) < len) {
+            if (sizeof(strncat(pathname, filename, len)) < len) {
                 if (stat(pathname, &stat_buf) == 0) {
                     return true;
  1. Run make from the root of the repository
  2. Run bin/nqc to make sure it works

Using ncq with the RCX

This assumes you're using my LEGO_RCX Tower

  1. Download the last, official LEGO firmware from someplace on the internet. It's called firm0332.lgo and I got my copy from

  2. Turn on the RCX, make sure the Arduino has the firmware flashed, and the RCX Hack microshield are installed on the Arduino. The following line assumes the Arduino was on COM15:

nqc -S/dev/ttyS15 -firmware firm0309.lgo

The screen on the RCX should start counting up. It counts pretty high before it finished with a fancy little tune.

  1. Grab the examples from and compile/download one to the RCX. The following is 1_simple.nqc:
task main()

bin/nqc -S/dev/ttyS15 -d ../NQCTutorialSamples/1_simple.nqc

  1. Build a fun robot, power on the RCX, and hit the play to see the program execute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.