Skip to content

Instantly share code, notes, and snippets.

@janjongboom
Last active February 24, 2023 14:40
Show Gist options
  • Save janjongboom/94d575526a689687a6b8 to your computer and use it in GitHub Desktop.
Save janjongboom/94d575526a689687a6b8 to your computer and use it in GitHub Desktop.
Firefox OS / JanOS on Raspberry Pi with GPIO support

This does NOT work on Raspberry Pi 2!

  1. Obtain a 8GB (or bigger) SD Card
  2. Download disk image from http://janos.io/builds/fxos-pi-gpio.img.zip and unzip
  3. Put SD card in your computer
  4. Find out where your SD card is mounted (BE REALLY SURE ITS THE RIGHT DEVICE, IT WILL BE WIPED COMPLETELY!!!), f.e. /dev/disk5 on OSX
  5. On Linux, run: sudo dd bs=4M if=fxos-pi-gpio.img of=/path/to/your/disk
  6. On OSX, run: sudo dd bs=4m if=fxos-pi-gpio.img of=/dev/rdisk5 (do rdisk, not disk here!)
  7. When it's done put it in your Pi and start up
  8. The demo's are wired like this: yellow LED on GPIO2, red LED on GPIO3, button (wire it as pulldown) on GPIO26.

Write your own apps

  1. Grab this repo: https://github.com/jan-os/janos/tree/gpio
  2. Check out apps/system/js/my-app.js for examples
  3. Go on the same network as the device and run nmap --open -p 5555 192.168.2.* (if 192.168.2 is your IP range of course) and use the IP in next step
  4. Connect to the device via adb: adb connect 192.168.2.100
  5. Verify that it works by running adb logcat, should see a lot of stuff going on
  6. Run make install-phone to update
  7. To debug, use WebIDE

Example of the API

Highly experimental, but to open pin 3 for output, set it to HIGH and then release it again:

navigator.gpio.setPinMode(3, 'output')
  .then(pin => {
    pin.writeDigital(true)
      .then(() => console.log('OK!'))
      .catch(ex => console.error('NOK!', ex));
  });

Only does digital pins at the moment.

Attribution

Porting Firefox OS to Rpi is all done by Chris Jones. I just wrote the Gecko APIs that make GPIO possible.

@SunboX
Copy link

SunboX commented Feb 27, 2015

This is how I did it on OSX

I put the downloaded and un-zipped fxos-pi-gpio.img in a folder called RPi_Image. Then:

sunbox:RPi_Image sunbox$ cd ./RPi_Image/

Make sure your SD-Card is unconnected and run:

sunbox:RPi_Image sunbox$ df -h
Filesystem                          Size   Used  Avail Capacity   iused    ifree %iused  Mounted on
/dev/disk2                         237Gi  217Gi   20Gi    92%  56909854  5313095   91%   /
devfs                              191Ki  191Ki    0Bi   100%       666        0  100%   /dev
map -hosts                           0Bi    0Bi    0Bi   100%         0        0  100%   /net
map auto_home                        0Bi    0Bi    0Bi   100%         0        0  100%   /home
map -fstab                           0Bi    0Bi    0Bi   100%         0        0  100%   /Network/Servers
localhost:/aBCdEFgH42i4242xxxYYYY  237Gi  237Gi    0Bi   100%         0        0  100%   /Volumes/MobileBackups
/dev/disk3                         698Gi  506Gi  192Gi    73% 132726923 50254917   73%   /Volumes/Data

Now connect your SD-Card and run the command again:

sunbox:RPi_Image sunbox$ df -h
Filesystem                          Size   Used  Avail Capacity   iused    ifree %iused  Mounted on
/dev/disk2                         237Gi  217Gi   20Gi    92%  56910914  5312035   91%   /
devfs                              197Ki  197Ki    0Bi   100%       680        0  100%   /dev
map -hosts                           0Bi    0Bi    0Bi   100%         0        0  100%   /net
map auto_home                        0Bi    0Bi    0Bi   100%         0        0  100%   /home
map -fstab                           0Bi    0Bi    0Bi   100%         0        0  100%   /Network/Servers
localhost:/aBCdEFgH42i4242xxxYYYY  237Gi  237Gi    0Bi   100%         0        0  100%   /Volumes/MobileBackups
/dev/disk3                         698Gi  506Gi  192Gi    73% 132726923 50254917   73%   /Volumes/Data
/dev/disk4s1                        50Mi   10Mi   40Mi    21%       512        0  100%   /Volumes/BOOT
/dev/disk4s7                       1.8Gi  1.2Mi  1.8Gi     1%         0        0  100%   /Volumes/SDCARD

You should see one (or more) new mounting points. In my case it's /dev/disk4s1 and /dev/disk4s7. Now unmount them (but leave the SD-Card conected!):

sunbox:RPi_Image sunbox$ diskutil unmount /dev/disk4s1
Volume BOOT on disk4s1 unmounted
sunbox:RPi_Image sunbox$ diskutil unmount /dev/disk4s7
Volume SDCARD on disk4s7 unmounted

Now let's flash the JanOS RPi image on the SD-Card. Replace the name of the partition (/dev/rdisk4) with your own one. Take the name of your un-mounted partition (in my case disk4s1) and add an r infront and remove the trailing s1:

sunbox:RPi_Image sunbox$ sudo dd bs=4m if=fxos-pi-gpio.img of=/dev/rdisk4

That's it! 😄

@SunboX
Copy link

SunboX commented Feb 27, 2015

Btw, booting it up takes some time! Don't be upset by the blinking cursor! 😃 After some minutes you should see the Firefox OS logo showing up, a few seconds later and the JanOS is up and running.

I couldn't get it connected using a direct LAN connection (crossover) to my MacBook Pro. But it worked when connecting the Raspberry Pi to my WiFi Router.

@janjongboom
Copy link
Author

Also if you like gaia better, clone the repo and just run make reset-gaia. Copy the api/gpio.js file over to your app if you want to do GPIO.

@SunboX
Copy link

SunboX commented Feb 27, 2015

Thx, but JanOS is absolutely ok. 😄 I'm trying to build a smart washing machine interface for demo purpose. So I don't need all the gaia stuff. Just some HTML5 interface that has a REST API and controls some hardware (LED's by now - for demo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment