#VSCode – Installing Visual Studio Code @code in a #RaspberryPi, run as root, fix black screen (Updated)

Buy Me A Coffee

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

wget https://packagecloud.io/headmelted/codebuilds/gpgkey -O
- | sudo apt-key add –

Then run this command

curl -L https://code.headmelted.com/installers/apt.sh | sudo bash

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

sudo apt-get install code-oss=1.29.0-1539702286

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

The following command will remove the hold for Visual Studio Code

sudo apt-mark unhold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Another update, is a command to run VSCode as root

# open VSCode in default source code folder with root
sudo code-oss --user-data-dir=/home/pi/src/vsCodeUsrData

Of course this is not the best way to use VSCode, however something it helps 😀

Note: Due some Deep Neural Network and docker process, my device is starting to heat a lot, so I’ll try a next generation cooler like this one: Blink Blink ICE Tower CPU Cooling Fan for Raspberry Pi (Support Pi 4)

Happy Coding!

Greetings @ Toronto

El Bruno

References

My posts on El Bruno

Advertisements

#RaspberryPi – Where is my Task Manager? let’s try #htop

Hi !

As a Windows user, I use task manager a lot. You know that moment when

  1. Your PC start to work very slow
  2. You press CTRL+SHIFT+ESC to open Task Manager
  3. Select the not amicable process
  4. And Kill it !

Bonus: another group of people uses a more classic way

  1. Press CTRL+ALT+DEL
  2. Select Task Manager

These days where I’m doing part of my developer work in a Raspberry Pi 4 (see references), I was also in the need for a “Task Manager”. So a quick Bing/Google search pointed a couple of products, and htop seems to be a very popular one. And I also like the official product description

This is htop, an interactive process viewer for Unix systems. It is a text-mode application (for console or X terminals) and requires ncurses.

Official htop page (see references)

It seems that initially the product was created for Unix, and now supports FreeBSD, OpenBSD, macOS, and more. And, of course, it runs on Raspbian.

Question: Should I write a post on how to install Raspbian for Raspberry Pi? My guess is no, there are so many of this already out, but ... if get bored.

Before I move on, let’s take a look at htop running in my device, while I’m building a docker image using some amazing TensorFlow image analysis models.

The way to install htop is very straightforward.

sudo apt-get install htop

Then you can launch the app with

htop

Super Easy ! And again, the UI gives you a lot of very useful information, and because Linux users are heavy on commands and not mouse, 99% of the actions to control the app are using these commands

  • F1 – Help (explains everything, always nice)
  • F6 – SortBy (You can sort the list processes with this option. Sorting by user, CPU usage and memory usage can be useful.)
  • F9 – Kill (You can select a process and send a kill signal)
  • F10 – Quit (sometimes you gotta leave htop)
Note: Get the commands and learn from David Walz post (see references)

Happy Coding!

Greetings @ Burlington

El Bruno

References

#VSCode – Let’s do some #Git dev in #RaspberryPi (GitHub and Azure DevOps!)

Buy Me A Coffee

Hi!

In my previous posts I wrote about how to prepare a developer station with a Raspverry Pi 4. I wrote on how to install Visual Studio Code, how to install .Net Core and how to build and run C# projects. Of course, the next step is to work with Git.

The command to install git is

sudo
apt-get install git

However, I already have Git installed. I haven’t checked, but it seems to me that the latest Raspbian distro includes by default git. I was hoping that VSCode will recognize and use this, but in order to work with Git in VSCode I need some extra work in the IDE settings.

raspberry pi git installed but not integrated in visual studio code

I was able to clone some repositories from GitHub and Azure DevOps, directly from bach

raspberry pi 4 git clone azure devops repository

So, let’s fix Visual Studio Code and Git integration. This one is very easy, I just need to go to Settings, search for Git and define the Git path for VSCode.

raspberry pi 4 visual studio code preferences git

In order to find the git path, we need to use the [which] command

pi@rpidev3:~ $ which git

/usr/bin/git

My got location is [/usr/bin/git].

I’m not a command line dude! I like User Interfaces, so now it’s time to open one of the cloned repositories in Visual Studio Code. I can see that VSCode recognices Git and I can start to commit my files.

raspberry pi 4 visual studio code using git

This is also a perfect moment to define Git user name and user email.

git config --global user.email "email@email.com" 
git config --global user.name "your name"

I like to do this in the Terminal in VSCode, just to check all is working fine.

Happy Coding!

Greetings @ Burlington

El Bruno

References

#VSCode – Installing Visual Studio Code in a #RaspberryPi, a couple of lessons learned – @code

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

wget https://packagecloud.io/headmelted/codebuilds/gpgkey -O
- | sudo apt-key add –

Then run this command

curl -L https://code.headmelted.com/installers/apt.sh | sudo bash

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

sudo apt-get install code-oss=1.29.0-1539702286

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Happy Coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – Running a #python script in a Python Virtual Environment on reboot / startup

Hi!

Adrian Rosebrock is a very smart person who has tons of great resources about Computer Vision in PyImageSearch.com. Most of them are with Python, and he also have some of them focused on how to perform CV using OpenCV in a Raspberry Pi.

In the post [Running a Python + OpenCV script on reboot, see resources] he explains how to automatically run a Python script when a Raspberry Pi starts. He uses python virtual environments, so the first 2 commands are focused on to load the virtual env. Then, move to the app folder and run the python script.

source ~/.profile
workon cv
cd /home/pi/pi-face-recognition
python startup.py

Something like this:

python source and cv on raspberry pi.

The suggested approach consists on create a Schell Script [.sh file] with these lines and add them to the auto start. However, once you create the file and test it, there seems to be an issue with the Source command.

python source not working on SH file

Ok, so no source command in an SH file. I started to think on install all my python dependencies directly in the main user, however the idea of working with virtual environments is very useful for me. It was to read online about Linux, python and more.

Note: Before moving forward, I may need to add some context. I need to run my python script in a Terminal. My device will always auto-start with a 3.5 inches touch screen and a camera, so I need some GUI loaded.

This is an excellent article on how to add actions to the Raspberry Pi start-up [How to Execute a Script at Startup on the Raspberry Pi, see resources]. So I added my SH file here and it didn’t work and I need to figure out how to load a virtual environment and run a python script.

After a couple of tests, I realized that all the files I need are part of the virtual env location in the device.

raspberry pi python folder for virtual envs

So, I only need to add the full path to my command to make it work without the and [workon] command. My complete command will became:

/home/pi/.virtualenvs/cv/bin/python /home/pi/pi-face-recognition/startup.py

So, I edited my autostart file adding this command

raspberry pi auto start file launching python script with a virtual env

And done! My python script running on a python virtual environment on the device startup is working!

Happy coding!

Greetings @ Toronto

El Bruno

Resources

#Python – How to create a Virtual Environment in #Windows10 (Easy one, and brain backup!)

Hi!

Quick post today, and mostly a reminder on how to create a Virtual Environment in Python in Windows 10. I’ve been doing this mostly in my Mac and my Raspberry Pi, and I always forget how to do this on Windows, so … I’ll write this post to have this

Install Python3.

Download the installers from the official Python source (see references). I usually install it on the root of my C: hard drive and name it with the version. In example: c:\Python37_64 folder.

Remember to also add this folder and the Scripts folder to the Environment Variables.

Note: Once you start to install tools which uses Python, your OS becomes a nightmare. You will have your own installed python, the version installed with Visual Studio, the one with Visual Studio Code, another one for Anaconda.

I’m not sure if this is a best practice or not, but I usually remove all the other versions and keep mines in the root of the C: drive.

Ok, let’s go on.

For a new virtual environment named “testEnv”, open a command prompt and navigate to the python folder. Then run the command

python -m virtualenv testEnv

After a couple of seconds, the virtual Environment will be installed, and you can use it by run the [activate.bat] script. In this example

  • The virtual environment will be created at [c:\Python37_64\testEnv]
  • The virtual environment activate script will be at [c:\Python37_64\testEnv\Scripts\activate.bat]

So the full command sequence is similar to this one

Now you have your virtual environment up and running and you may want to start to add your own packages or tools. Like in example: Numpy or to list the installed packages

Finally, you may leave the virtual environment with the command

deactivate

Happy Coding!

Greetings @ Toronto

El Bruno

Resources

#Windows10 – Using W10 Mobile Hotspot on Holidays

Hi!

Big off-topic for today’s post. However, I think it’s worth sharing these workarounds, hoping they’ll be useful for someone else. Well, before starting a bit of context:

Last week we went on vacation with family and friends to the Caribbean. In general, having internet connectivity is not a priority. However, one of the Free Wifi policies was: Internet access via WiFi was free, but you could only authenticate 2 Devices per room.

In a family of 4 people, where each one has at least one device that requires an internet connection, I did not close the numbers. We did not need to be connected all 4 of us all day, but there were times where we needed at least 3 devices connected.

After investigating for a while, I realized that the filter of devices connected by room does not include ranges of IPs or Mac Address, so the Windows 10 option to create a Mobile Hotspot was an option. 3 clicks later we were already 4 devices connected to the internet, the test had been a success!

 

I3

The Bing search engine details the step by step necessary to enable a Mobile Hotspot in [ Use your PC as Mobile Hotspot ].

Open Mobile Hotspot Settings

Note: Until now I have only used MH as a hotfix in Hololens demos, it also works on holidays!

Happy coding!

Greetings @ Toronto

El Bruno

#Windows10 – Usando W10 Mobile Hotspot en vacaciones

Buenas!

Menudo off-topic me marco hoy, pero vale la pena compartir estos workarounds, esperando que le sirvan a alguien. Pues bien, antes de comenzar un poco de contexto:

La semana pasada nos fuimos de vacaciones con familia y amigos al Caribe. Por lo general, tener conectividad a internet no es una de las prioridades, sin embargo, una de las políticas de Free Wifi me llamo la atención (hacía mucho que no la veía). El acceso a internet vía WiFi era gratis, pero solo podías autenticar a 2 Devices por habitación.

En una familia de 4 personas, donde cada uno tiene mínimo un device que requiere conexión a internet, no me cerraban los números. El detalle es que no necesitábamos estar conectados todo el día las 4 personas, pero había momentos donde necesitábamos al menos 3 devices conectados.

Despues de investigar un rato, me di cuenta de que el filtro de devices conectados por habitación no incluye rangos de IPs ni Mac Address, con lo que la opción de Windows 10 de crear un Mobile Hotspot era una opción. 3 clicks después ya estábamos 4 devices conectados a internet, la prueba había sido todo un éxito !!!

I3

El buscador de Bing te detalla el paso a paso necesario para habilitar un Mobile Hotspot en [ Use your PC as Mobile Hotspot ].

Open Mobile Hotspot Settings

Nota: Hasta ahora solo habia usado MH como hotfix en demos de Hololens, tambien sirve en vacaciones!

Happy coding!

Saludos @ Toronto

El Bruno

#HowTo – Add #360 Photos in posts in wordpress.org

Hi!

A few months ago I get, as a family present, a Ricoh Theta SC 360 camera. Mostly, for personal use and the truth is that I have a great time with this new device. Compared with other models of the Ricoh Theta range, the main difference is that this model does not support Live Streaming. If at any time I see that this is a necessity, then I will evaluate again what options there are in the market.

Currently, one of the activities where I use the camera is when I participate in an technical event. If there is time and everyone is in ok with this, I activate the [Interval Shooting] mode and from a fixed position I capture a 360 photo every N minutes. The result is a very pleasant Time Lapse.

When sharing photos 360, the only platform on social networks that is really prepared for these contents is Facebook. Twitter, Instagram and the others are several steps behind. And, as always, wordpress.org is a world apart.

Important: My blog is on wordpress.org, so what I write in this post only applies to similar scenarios.

Well, when you add a 360 photo to WordPress, you have something similar to the next picture

R0010184

It is not what we expect, much less in a 360 photo. The official solution is to use a Plugin to view photos or videos in 360-degree format. In the Marketplace of plugins there are many free and paid options.

This is simple when you manage your own WP, in my case, I need to update a plan to something that is 10 times more expensive than what I currently pay

I2

After doing some research about it, I’ve found a WordPress post of the year 2016 where they commented that Out-Of-The-Box WordPress will support 360 content. The syntax that we should use is quite simple

I3

Applying this scheme my initial image changes a lot and for the better. It can be seen in 360 mode

Happy coding!

Greetings @ Burlington

El Bruno

References

#HowTo – Agregando imágenes #360 en nuestros posts en wordpress.org

Buenas!

Hace unos meses que tengo en mis manos una cámara 360 Ricoh Theta SC para uso personal y la verdad es que me lo paso genial. Comparadas con otros modelos de la gama Ricoh Theta, la principal diferencia es que este modelo no soporta Live Streaming. Si en algún momento veo que esto es una necesidad, pues evaluare nuevamente que opciones hay en el mercado.

Actualmente, una de las actividades donde utilizo la cámara es cuando participo en algún evento. Si hay tiempo y todos están de acuerdo activo el modo [Interval Shooting] y desde una posición fija capturo una foto 360 cada N minutos. El resultado es un Time Lapse bastante agradable.

Al momento de compartir las fotos 360, la única plataforma en redes sociales que realmente está preparada para estos contenidos es Facebook. Twitter, Instagram y los demás, están varios pasos por detrás. Y, como siempre, wordpress.org es un mundo aparte.

Importante: mi blog está en wordpress.org. Con lo que lo que escribo en este post solo aplica para escenarios similares.

Pues bien, al momento de agregar una foto 360 a WordPress el resultado que tenemos de la misma es el siguiente

R0010184

No es lo que esperamos ni mucho menos en una foto 360. La solución oficial es utilizar algún Plugin para visualizar fotos o videos en formato 360 grados. En el Marketplace de plugins hay muchas opciones gratis y de pago.

Esto es simple cuando gestionas tu propio WP, en mi caso, necesito actualizar un plan a algo que es 10 veces mas caro que lo que actualmente pago

I2

Después de investigar un poco al respecto, me encontré con un anuncio de WordPress del año 2016 donde comentaban que Out-Of-The-Box WordPress soportara contenido 360. La sintaxis que debemos utilizar es bastante simple

I3

Aplicando este esquema mi imagen inicial cambia mucho y para mejor. La misma se puede ver asi en modo 360

Happy coding!

Saludos @ Burlington

El Bruno

References