NixOS Arduino (ESP8266) programming?

737 views
Skip to first unread message

Matthias Beyer

unread,
Jan 1, 2018, 7:59:25 AM1/1/18
to nix-...@googlegroups.com
Hi,

I have a ESP8266 and I want to program it from NixOS.

Unfortunately, using the arduino ide is not that easy on NixOS,
because it fetches its own toolchain which cannot be used on nixos as
it seems (because of linking).

Is there anyone out there with experience programming ESP8266 from
NixOS?

I tried using a chroot env (FHSUserEnv) but that doesn't work either.
It fails with

warning: espcomm_sync failed
error: espcomm_open failed

And so on.
I hope someone can help me here.

--
Mit freundlichen Grüßen,
Kind regards,
Matthias Beyer

Consider switching to free software.
It adds value to your life.
https://www.gnu.org/
signature.asc

Felix Richter

unread,
Jan 1, 2018, 8:21:40 AM1/1/18
to Matthias Beyer, nix-...@googlegroups.com
Hey,

On Mon, Jan 01, 2018 at 01:59:21PM +0100, Matthias Beyer wrote:
> Hi,
>
> I have a ESP8266 and I want to program it from NixOS.
>
> Unfortunately, using the arduino ide is not that easy on NixOS,
> because it fetches its own toolchain which cannot be used on nixos as
> it seems (because of linking).
>
> Is there anyone out there with experience programming ESP8266 from
> NixOS?

The last thing i used for building esp8266 was the platform.io toolchain. It
uses fhsuserenv to get the downloaded compilers running.
Simply uploading new firmware with esptool works with the package in nixpkgs
without any issues.

For hotfixing the arduino toolchain you can patchelf the binaries in .arduino
somewhere.

>
> I tried using a chroot env (FHSUserEnv) but that doesn't work either.
> It fails with
>
> warning: espcomm_sync failed
> error: espcomm_open failed

The error looks like the serial console cannot be opened, this can be related
to multiple issues:
1. esp not connected correctly to the serial console
2. permission errors
3. you need to explicitly set which serial port should be used

Regards,

Felix
signature.asc

Gemini Lasswell

unread,
Jan 2, 2018, 2:11:01 PM1/2/18
to nix-devel
Hello,


On Monday, January 1, 2018 at 4:59:25 AM UTC-8, Matthias Beyer wrote:
> Hi,
>
> I have a ESP8266 and I want to program it from NixOS.

I've written an almost-finished patch for nixpkgs which adds an
arduinoWithPackages which works like emacsWithPackages, and it happens
to include the ESP8266 board definition. I just uploaded it to
https://github.com/gazally/nixpkgs/tree/arduino. It's based on master,
but you could cherry-pick its two commits into your own nixpkgs repo
and then use an expression like this one:

    pkgs.arduinoWithPackages (apkgs: with apkgs; [ esp8266 ])

to make an arduino IDE which includes the ESP8266 toolchain. I've used
it with Adafruit's ESP8266 breakout.

This patch has been almost-finished for several months, because I got
distracted by a microcontroller project. One part that isn't finished
is the documentation, but you might find what I've written so far to
be helpful. The other todo is adding more board and library
definitions, as the only ones it has now are the ones I use, but you
could use those as models for adding more.

Regarding your communication problem, if you're connecting your
ESP8266 via USB, have you written a UDEV rule for it?

Best,
Gemini

Matthias Beyer

unread,
Jan 4, 2018, 6:23:25 AM1/4/18
to Gemini Lasswell, nix-devel
Hi,

On 02-01-2018 11:11:00, Gemini Lasswell wrote:
> I've written an almost-finished patch for nixpkgs which adds an
> arduinoWithPackages which works like emacsWithPackages, and it happens
> to include the ESP8266 board definition. I just uploaded it to
> https://github.com/gazally/nixpkgs/tree/arduino. It's based on master,
> but you could cherry-pick its two commits into your own nixpkgs repo
> and then use an expression like this one:
>
> pkgs.arduinoWithPackages (apkgs: with apkgs; [ esp8266 ])
>
> to make an arduino IDE which includes the ESP8266 toolchain. I've used
> it with Adafruit's ESP8266 breakout.

I love you!

>
> Regarding your communication problem, if you're connecting your
> ESP8266 via USB, have you written a UDEV rule for it?
>

Nope. I see the ESP in dmesg as /dev/ttyUSB0 so I thought that should
be enough. It isn't, I suppose?

Thank you and also thanks to Felix for his mails.
signature.asc

Matthias Beyer

unread,
Jan 13, 2018, 5:09:28 AM1/13/18
to Gemini Lasswell, nix-devel
Hi,

Maybe you remember our conversation...

On 02-01-2018 11:11:00, Gemini Lasswell wrote:
> On Monday, January 1, 2018 at 4:59:25 AM UTC-8, Matthias Beyer
> wrote:
> > Hi,
> >
> > I have a ESP8266 and I want to program it from NixOS.
>
> I've written an almost-finished patch for nixpkgs which adds an
> arduinoWithPackages which works like emacsWithPackages, and it happens
> to include the ESP8266 board definition. I just uploaded it to
> https://github.com/gazally/nixpkgs/tree/arduino. It's based on master,
> but you could cherry-pick its two commits into your own nixpkgs repo
> and then use an expression like this one:
>
> pkgs.arduinoWithPackages (apkgs: with apkgs; [ esp8266 ])
>
> to make an arduino IDE which includes the ESP8266 toolchain. I've used
> it with Adafruit's ESP8266 breakout.

Unfortunately, this does not build for me (I cherry-picked your two
commits onto 33a4de2941d49269229267c13eec02551b4437b6 which is my
current unstable branch):

+nix-repl> :b pkgs.arduinoWithPackages (apkgs: with apkgs; [ esp8266 ])
[...]
unpacking source archive /nix/store/qqfqvz0hfjqlmzv8cii0rqzwy15r54di-mkspiffs-0.1.2-linux64.tar.gz
unpacking source archive /nix/store/vbrlkgjpg5nkkg42zyscl2hp5q10kzwn-linux64-xtensa-lx106-elf-gb404fb9.tgz
source root is /tmp/nix-build-esp8266-2.3.0.drv-0
setting SOURCE_DATE_EPOCH to timestamp 1466143132 of file /tmp/nix-build-esp8266-2.3.0.drv-0/esptool-0.4.9-linux64/esptool
patching sources
configuring
no configure script, doing nothing
building
no Makefile, doing nothing
installing
cp: cannot stat 'Arduino-09826c6d87e54c15422da90f060377c9ef188947-src/': No such file or directory
builder for ‘/nix/store/9spy256psaj9bj2wdfj46hvbpcdfy1h2-esp8266-2.3.0.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/h1lkyh5pavskzn3dihn6qbr8zpv1ypm1-arduino-with-packages-1.8.5.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/h1lkyh5pavskzn3dihn6qbr8zpv1ypm1-arduino-with-packages-1.8.5.drv’ failed
+nix-repl>

I'm not sure whether this is my fault (missing patches or something)
or whether the branch contains the failure.

>
> Regarding your communication problem, if you're connecting your
> ESP8266 via USB, have you written a UDEV rule for it?

I didn't even know that this is required. Do you have a snippet for
me? :-)
It's my first time doing anything with external hardware, youknow :-)
signature.asc

Gemini Lasswell

unread,
Jan 15, 2018, 8:18:40 PM1/15/18
to Matthias Beyer, nix-devel

Hi Matthias,

Matthias Beyer writes:

> Unfortunately, this does not build for me (I cherry-picked your two
> commits onto 33a4de2941d49269229267c13eec02551b4437b6 which is my
> current unstable branch):

It doesn't build for me either on current unstable. Something apparently
changed in unstable since I wrote it. As it happens I saw this error
last week when making an updated esp8266 package and figured out how to
fix it. That commit is now on my github branch so please give it a try.

> warning: espcomm_sync failed
> error: espcomm_open failed

I took another look at this and I now think this means that the serial
over USB connection is up but the bootloader on the ESP8266 isn't
responding. On my Adafruit boards you enable the bootloader by holding
the GPIO0 button while pressing and releasing the RESET button. If you
have a different ESP8266 board you could check the manufacturer's
website for bootloader instructions. Another possibility is that the
baud rate isn't set correctly.

Best,
Gemini
Reply all
Reply to author
Forward
0 new messages