How to program your Lego Bot with NXC (on a Mac)
When starting with Lego programing, Mac users are often met with difficulties when it comes to language selection. Whilst many languages exist that one could write mindstorm-programs with, not many are OSX compatible. In reality - the only viable option apart from the visual lego language is NXC.
Starting with NXC is however also a big hurdle if you’re not used to working with the terminal. Here’s where this short guide comes in.
What you’ll need
To get started with developing there’s a few things you’ll need.
- Your charged lego robot
- A text editor (I recommend Atom from Github!)
- A USB-cable
Installation
Lets start off by downloading the files we need.
- Go to mindstorms downloads
- Scroll down to “NEDLADDNING AV NXT-PROGRAMVARA (PC/MAC)” and select the NXT Fantom driver.
- Install the NXT Fantom Driver.
- Go to the bricxcc sourceforge page for NBC and download the latest executable for Mac
- Extract the contents for the .tgz-file you just downloaded in a location of your choice.
Using NXC and running the code
While developing, you write your code in a text editor as per the NXC documentation. When you want to try out the code on the robot, you do the following:
- Open up a terminal and navigate to the folder. If you placed the contents on your desktop, the command you need to run will be
cd ~/Desktop/<name of the folder>
- Plug in your lego robot to your mac.
- Run the following command and replace “file-path” with the path to your .nxc file. If you’re having trouble finding the path, simply drag the .nxc file into the terminal window.
./nbc -d file-path
If you want to, you can replace the “-d” with a “-r” to execute the code automatically when it’s downloaded to the robot.
That’s all there is to it! Happy Hacking! :)