Espruino on the Pi (with WiringPi)

Posted on
Page
of 2
/ 2
Next
  • I'm not sure if anyone has tried it recently, but Espruino has been available for the Pi for years.

    Having discovered wiringPi a few weeks ago, I decided to have another play around. It actually makes Espruino on the Pi really interesting.

    When run with 'sudo' it has...

    • Much faster IO, making software SPI a sensible option
    • All the network and filesystem stuff you'd expect
    • A proper setWatch that uses interrupts
    • Hardware PWM on D1, although it looks like 'softPwm' could work just fine
    • USART support (Serial1.setup(9600,{....path:"/dev/ttyUS­B0"}))

    With the newest Raspbian images, installation is pretty simple too. On a clean install, log in and do:

    git clone git://git.drogon.net/wiringPi
    git clone https://github.com/espruino/Espruino.git­
    cd wiringPi
    ./build
    cd ../Espruino
    make
    

    Anyway, the exciting thing is setWatch really. I just plugged a 433Mhz radio receiver straight into one of the GPIOs and I can actually decode 433Mhz signals with it - using the exact same code that was used on the Espruino board.

    Given the price of Raspberry Pis now this could make a really interesting all-JavaScript base station. The extra oomph of the Raspberry Pi means it should be a lot more reliable when it comes to decoding radio signals.

  • ...no deserters please ;-) ... I know that power consumption - more precisely: power frugality - cannot be beaten by any other platform. But obviously speed helps the JavaScript part of Espruino a lot. Are there options available for a less power frugal but much faster chip on Espruino regular and pico board?

  • I don't think there is anything that would fit in the same form factor.

    Having said that you can overclock the chips. The f103 in the original board isn't great as afaik if you want USB then 72mhz is mandatory. However the f401 allows different clocks while keeping USB running.

    If the process tech and core is the same as the F407 then it might be possible to double the clock speed to 168mhz

  • Espruino everywhere!!

    I just purchased one of these ARMinARM boards for one of my Raspberry Pis -> https://www.tindie.com/products/onandoff­ables/arminarm/

    It's really a nicely done board that turns your RasPi into an ARM development platform.One of the exciting things is there is an Espruino ready to run on it.

    With wiringPi and Espruino on the Pi and now this board running Espruino, I can easily run Espruino everywhere (obviously part of your plans for world domination!)

    Well done!!

    Rick

  • You mention the software SPI, but what about the hardware SPI and I2C?

    Bob

  • Think I will be using this option for my little project :D

  • @bob_dvb the software SPI and I2C isn't implemented yet, but it should be very easy to do using the WiringPi library.

    It's just a matter of 'filling in the blanks' in targets/linux/jshardware.c - I just don't have time to do it myself at the moment.

  • Is there a guide any where on how to set up and run projects on the raspberry pi?

    Thanks

  • Have you managed to build the binary?

    If so, there's ./espruino --help, although there is no 'getting started'. If you wanted to write one it'd really be appreciated though!

    Basically you can get a command-line just with ./espruino, or can run a script with ./espruino sourcefile.js. To get something running all the time, and to still have access to the command-line when you want it, you could run espruino inside screen.

  • Is there a way to exit from Espruino back to Raspbian? I know I can type reset() but that command only resets Espruino environment but I stay in Espruino command prompt. I want to exit to Linux, how to do that?
    Thanks!

  • Just type quit(). Ctrl+C should work too.

  • quit() works, CTRL+C doesn't (and I think it is good!). I found I can kill espruino process from other terminal but quit() command is better way. Thank you!

  • Where did you get the binary from? the zip file?

    If so, try getting the latest version - I released 1v72 yesterday, and that would have had the Ctrl+C, plus a few other improvements.

  • CTRL-C doesn't work in 1v73 but as I said , it is not problem for me. Maybe that CTRL+D should be used (UNIX, hangup). I connect to Rasberry over ssh, maybe that CTRL-C is not transferred...

    I noticed something strange with 1v73 (git). I enter ".help" and after that quit() and I see some error report or what is that:

     1v73 Copyright 2015 G.Williams
    
    >.help
    =undefined
    Uncaught SyntaxError: Got '.' expected EOF
     at line 1 col 1
    .help
     ^
    >quit()
    =undefined
    >
    USED VAR #26:  #26[r1,l0] Function { 
        #27[r1,l2] Name String [2 blocks] "prototype"      #29[r1,l1] Object { 
            #30[r1,l2] Name String [2 blocks] "constructor"          #26[r1,l1] ...
     
          } 
      }
    USED VAR #27:  #27[r1,l0] Name String [2 blocks] "prototype"    #29[r1,l1] Object { 
    ....
    USED VAR #31:  #31[r0,l0] Unknown 38 
    pi@rpi ~/Espruino $ 
    
  • Thanks for the report - I've just made a bug for this.

    The Linux versions of Espruino check for memory leaks on exit, and it looks like that particular syntax error caused a memory leak.

    It's not much to worry about though - you'll lose a few bytes of memory each syntax error until this is fixed - but then you have several hundred MB to play with :)

  • Actually just an update on this - it's not a problem with the interpreter at all.

    It's just that on exit Espruino was showing all memory that was left allocated. It should have run a garbage collection pass beforehand, so it could be sure that the stuff it was showing was actually a memory leak, and not just stuff that was left hanging around.

  • The build works on a Pi2, but not all of the tests pass:

    ----------------------------------------­----------
     227 of 232 tests passed
    FAILS:
    tests/test_new_nested.js
    tests/test_pipe.js
    tests/test_new_nested2.js
    tests/test_language.js
    tests/test_number_constructor.js
    ----------------------------------------­----------
    
    

    Are these required to pass, or just nice to have passes?

    Thanks.

  • That's fine - there are one or two tests in there that don't pass - to remind me of things that need doing :)

    test_pipe.js passes on mine, but it's probably just because test.txt doesn't exist,

  • OK, thanks :)

  • quit() doesn't work in the last build.

     _____                 _ 
    |   __|___ ___ ___ _ _|_|___ ___ 
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v75 Copyright 2015 G.Williams
    
    >quit();
    =undefined
    Uncaught Error: Function "quit" not found!
     at line 1 col 1
    quit();
     ^
    

    Update: this is strange but "quit" works. I did "make clean; make" and "quit" works after rebuild. But it is possible that I only miss something, that I did some action and espruino damaged internal data structures and that was a reason why "quit" was not working.

  • Thanks for the update. If you used save() it's possible that the saved code was in a format from an older version of Espruino, and that it confused it?

  • SOLVED! It was mostly a "betwwen-the-ears" problem! ;)

    I looked through the code until I found what I needed to know. The call to "wiringPiSetup" confirmed that the normal GPIO numbers should be used (I'm using sudo). I didn't want to risk blowing up any GPIO pins by putting buttons on output pins. However, after reading the code, it looks like the correct pin mode is always set for reads or writes, which probably means it's more difficult to blow up the pins.
    Anyway, it works!

    Original message is here, so you can still read about the "problem":

    I've got Espruino compiled, built and running on the raspberry pi.
    WiringPi is (obviously) installed and working too.
    Before I go and do anything stupid with the GPIO pins I have a pretty basic question: How do I actually use Espruino and WiringPi together?
    I'm looking for some simple example code that will turn raspberry pins on and off, or set pwm values. I've looked at the 433Mhz example and digitalPulse is used there. However, I'm still not sure about the actual pin names/numbers to use with the raspberry pi GPIO pins.
    Simple examples would be greatly appreciated!

  • Great - glad you got it sorted!

    Yes, unless you use pinMode first, Espruino sets the pin mode automatically. It's good you checked though, the Pi's GPIO is more delicate than the STM32 chips that are on the Espruino board :)

  • My 9 year old son is an avid user of the scratch programming language and we are working on a modest weather station together. We have light, humidity and temperature sensors attached to a Raspberry Pi. The Raspberry Pi is headless which really limits his options for programming the thing. Thanks to Google I wound up here and quickly configured the Raspberry Pi to work with the Web IDE.

    On my son's laptop running Chrome I installed the IDE. I made the following two configuration adjustments:
    Settings->General->Overwrite JavaScript with Graphical Editor->Check the Box (true)
    Settings->Communications->Baud Rate->115200

    As root (relax, this isn't a mission critical server) I did the following:

    cd /root
    git clone git://git.drogon.net/wiringPi
    git clone https://github.com/espruino/Espruino.git­
    cd wiringPi
    ./build
    cd ../Espruino
    make
    

    Next I installed the socat program.

    apt-get install socat
    

    Then, I determined the TTY device of my serial port

    root@weather:~# dmesg | grep tty
    [    0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0x10 bcm2708.serial=0x561ae60d smsc95xx.macaddr=B8:27:EB:1A:E6:0D bcm2708_fb.fbswap=1 bcm2708.disk_led_gpio=47 bcm2708.disk_led_active_low=0 sdhci-bcm2708.emmc_clock_freq=250000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
    [    0.001749] console [tty1] enabled
    [    0.141194] 20201000.uart: ttyAMA0 at MMIO 0x20201000 (irq = 83, base_baud = 0) is a PL011 rev2
    
    

    In my case the serial device is 'ttyAMAo'

    Next I opened /etc/inittab in an editor and ensured that no programs were using /dev/ttyAMAo. Now that I think of it, you may also need to edit the grub config and remove any serial console parameters passed to the kernel. I leave this as an exercise for the reader.

    Finally, I added the following to /etc/inittab

    T0:23:respawn:socat SYSTEM:/root/Espruino/espruino FILE:/dev/ttyAMA0,b115200,raw
    

    Next I instructed init to re-read the configuration

    
    init q
    
    

    The Espruino prompt immediately appeared on the IDE. I switched to the graphical editor and it worked too. And just like that my son can explore physical computing on a Raspberry Pi using Espruino.

    Time to visit your store and order some boards. I see lots of little creations in his future.

  • That's great! Thanks for posting that up! I'd never really considered using the Web IDE with a Pi before, but it makes a lot of sense!

    A few weeks ago I made it so the Web IDE can connect to a network server. I wonder if you could somehow use that with Espruino on the Pi... Maybe just a telnet server or something?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino on the Pi (with WiringPi)

Posted by Avatar for Gordon @Gordon

Actions