Skip to content

Instantly share code, notes, and snippets.

@LiamPerson
Last active September 14, 2024 17:58
Show Gist options
  • Save LiamPerson/3455f99baee6ef49393cd91026a01b7e to your computer and use it in GitHub Desktop.
Save LiamPerson/3455f99baee6ef49393cd91026a01b7e to your computer and use it in GitHub Desktop.
Arch Linux Tutorial | How to build with the ESP32-CAM (AI Thinker) & Arduino IDE

How to build the example server for the ESP32-CAM (AI-Thinker) for the Arduino IDE from nothing on Arch Linux

Unlike most operating systems, there is a special trouble (for noobs) with performing this on Arch due to the amount of compiling from source.

Steps

Get the Arduino IDE (v1 because it is the best)

We want to run the v1 Arudino environment/IDE because it is the most compatible with tutorials online. If you are reading this you are probably a noob and following said tutorials.

  • Get base-devel and git: sudo pacman -S --needed base-devel git
  • Get the arduino package from the AUR repository: git clone https://aur.archlinux.org/arduino.git. As a side note: I like to put this in a new folder in my home directory called Applications so I can keep track of my apps.
  • Enter the folder of the package you just cloned with git: cd arduino
  • Add the GPG signature for Arduino so your build doesn't fail due to unverified keys: gpg --recv-keys 95FA6F43E21188C4
  • Update your local package cache so you don't get unknown package errors: sudo pacman -Syy
  • Build and install the package. Also add any depdencies you need: makepkg -si
  • You can now run the IDE using arduino

Get PySerial so you can access the serial module

If you try run off and build the sketch now you will get the following error: ModuleNotFoundError: No module named 'serial'. Let's fix that:

  • Get PySerial: sudo pacman -S python-pyserial

Get access to the correct devices

Now if you try and build you will notice a new error. You will find the editor lying to you saying A fatal error occurred: Could not open /dev/ttyS0, the port doesn't exist. Well guess what editor, it does. You just can't see it. Unfortunately, the editor does need to read and write to this device to be able to compile and deploy your code to the board. Let's give it access:

  • Get access to read and write on the device: sudo chmod a+rw /dev/ttyUSB0

This will give EVERYONE (every user on your computer) access to this device ... until you unplug it. Then it is back to root only again.

Connect a bunch of cables

Now we're ready to set up the hardware. Connect a bunch of cables to your board using a FTDI (red thing): Be careful when plugging in these cables as the manufacturers are sneaky and like to move around what pin position is actually for what pin. So make sure to check the text on your board before blindly plugging in cables.

An image I stole from a tutorial.

If you're wondering where I got my red thing (FTDI): Aliexpress: https://www.aliexpress.com/item/1005007395673301.html

Reset the board

Now you've done all that. Don't forget if the board had some code on it before you gotta wipe that sh!t off! To do this, you have to connect the GND to the IO0 pin. - Just like what I've illustrated below in this diagram I stole: Where the GND and IO0 pins are in an image I stole from a tutorial.

AND THEN you need to press the RST (reset) button while those cables are connected: Where the RST button lives.

Get board managers

Now we are ready to actually make the software product. To do this, we need to get the board manager for our board. Right now the Arduino IDE is simply too stupid to know of it.

  • In the Arduino editor, press CTRL+, to bring up the Preferences menu.
  • In the "Additional Boards Manager URLs:" text field add the following link: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json If you need more space here because you already have a list. Just click the double-rectangle looking icon and it will open up a bigger dialogue menu as shown below. Just add it under a new line.

The bigger dialogue menu

  • Now you need to download the board manager. Open the Board Manager under 'Tools' Where to find the board manager

  • Now search for esp32 and install the latest version.

Where esp32 is

Get the code and compile it

Ok, now we should be good to get the code and compile it. All we need to do is select the correct board, the correct port, and example.

  • This is the worst part of all. Finding the actual board. Select 'Tools' -> 'Boards' -> 'AI Thinker ESP32-CAM'. It can be very hard to find it but you will eventually. In Arch, the windowing sucks hardcore as well but just bear with it. Where the esp32-cam is

  • Now you have your board, get your port set correctly. It will very likely be /dev/ttyUSB0 The correct port

  • Just as a final safety measure, I also select the programmer Esptool: Selecting the programmer

  • Now you have all that set, select the example for streaming with this board. 'File' -> 'Examples' -> 'ESP32' -> 'Camera' -> 'CameraWebServer'. This will load all the code you need to get this running as a template you can use to edit as you desire! Selecting CameraWebServer

  • Let's make sure the template works first before we edit it though: Select the camera model by uncommenting #define CAMERA_MODEL_AI_THINKER (removing the // at the start) and commenting out any other models in that block/list Commenting out the correct board.

  • Now you just need to set your WiFi SSID (your network's name) and password like so: Setting the wifi

Compile it!

That's it. We're done. Now we just need to put it on the board.

  • Press the forward/next/right arrow in the editor to upload the software to your board: upload in the ide

  • The upload is complete when you see the message

Leaving
Hard resetting via RTS pin

Done uploading

  • IMPORTANT: Unplug the GRD and IO0 cables so you don't remove all your newly uploaded soft/firmware.

  • Now press the RST (reset) button again and you should now be able to discover your device using your router or nmap or whatever and connect to it using its IP http://<your board's ip address>!

You're done! πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰

@LiamPerson
Copy link
Author

LiamPerson commented Sep 14, 2024

Stole the board connections from: https://randomnerdtutorials.com/program-upload-code-esp32-cam/
I found this site pretty useful for the board's anatomy as well: https://lastminuteengineers.com/getting-started-with-esp32-cam/

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