Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Saturday, 9 July 2022

CircuitPython and MicroPython - – start file differences

CircuitPython and MicroPython have many similarities, but there are some major differences.

One of the most fundamental are the names of the files executed when the board is powered up.

Start up sequence

MIcroPython 

MIcroPython looks for two files in a set order in the root of its filesystem.

  • boot.py – this file is run when power is first applied to the board or when the board is reset. Probably not of interest in general unless you are modifying MicroPython.
  • main.py – this is the file that is either your program or starts your program. If it is present, it is run after the code in the boot.py file.

CircuitPython

CircuitPython looks for the following files in this order:

  • •code.txt
  • •code.py
  • •main.txt
  • •main.py.

References

https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/micropython-or-circuitpython

https://github.com/adafruit/circuitpython#differences-from-micropython

https://docs.circuitpython.org/en/latest/README.html#differences-from-micropython


Saturday, 8 January 2022

Installing CLANG on a Raspberry Pi

The following uses an 8GB Raspberry Pi 4.


Update and upgrade your installation

sudo apt update
sudo apt upgrade

Install CLANG

apt-get install clang-format clang-tidy clang-tools clang libc++-dev libc++1 libc++abi-dev libc++abi1 libclang-dev libclang1 liblldb-dev libllvm-ocaml-dev libomp-dev libomp5 lld lldb llvm-dev llvm-runtime llvm python-clang

Note: LLVM suggested apt call includes clangd, however it does not appear on the “current” Raspbian distribution (though I noted my version of CLANG is version 7 so later distributions might contain it).

Check it is in place.

clang++ --version


clang version 7.0.1-8+rpi3+deb10u2 (tags/RELEASE_701/final)
Target: armv6k-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/bin

Hello World

Create a C++ source file
#include <iostream>
int main(){
std::cout<<"Hello world\n";
return 0;
}

Save the file to a specific folder (I chose ~/Documents/Cplusplus/helloworld )

Change the working folder to its location
cd ~/Documents/Cplusplus/helloworld

Compile:
clang++ -std=c++17 -Wall -pedantic helloworld .cpp -o helloworld
Run
./helloworld


Install Visual Studio Code (Other IDEs are available)

Raspberry Pi has Visual Studio Code in its repository
sudo apt install code

Open Visual Studio Code and install the install the C/C++ extension (C/C++ from Microsoft).

Configuring Visual Studio Code

Other descriptions of configuring Visual Studio include additional editing of files, but the Raspberry Pi repository seems to cover a lot of it.
Open the folder in Visual Studio.
Open the CPP file.

Click on Run and select Start Debugging.
From the list of environments select C++(GDB/LLDB)
Select g++.exe - Build and debug active file.
This creates a new folder named .vscode in the current folder.
Within that folder are two JSON files: tasks.json and launch.json
The file tasks.json contains the arguments and the location of the clang compiler front end.


{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}



Use the above file as a reference.
The launch.json file contains information about what happens when Visual Studio Code starts to run the compilation.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"targetArchitecture": "ARM64",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: clang++ build active file",
"miDebuggerPath": "/usr/bin/lldb-mi"
}
]
}



The key element that is not in the default configurations elements is the targetArchitecture:
"targetArchitecture": "ARM64"
Add this to the file as shown above.
This removes the “Warning: Debuggee TargetArchitecture not detected, assuming x86_64.” warning message.


References

https://apt.llvm.org/
https://code.visualstudio.com/docs/setup/raspberry-pi
https://www.raspberrypi.com/news/visual-studio-code-comes-to-raspberry-pi/
https://solarianprogrammer.com/2018/04/22/raspberry-pi-raspbian-install-clang-compile-cpp-17-programs/
https://solarianprogrammer.com/2021/06/11/install-clang-windows-msys2-mingw-w64/
https://johnnn.tech/q/vscode-lldb-on-macos-error-when-starting-debugging-session/
https://code.visualstudio.com/updates/v1_50#_linux-arm-builds






Monday, 12 August 2019

Fortran on the Raspberry Pi

Introduction

My first programming job was in Fortran (Fortran 77 on an HP-150 with an HPIB connection to an I/O board). I have not used Fortran for probably thirty years but thought I should have a look at trying it on the Raspberry Pi.
Fortran is not just a very long lived language, unlike COBOL which has survived because core parts of the financial sector have stable working elements that they do not want disturbed, Fortran is still a developing system - its continued use in high powered mathematical processing celebrates the origin of its name "Formula translation".

Installation

Make sure that the operating system is up to date:
sudo apt-get update
sudo apt-get upgrade
Then install GFortran:
sudo apt-get install gfortran

First program

I added a Fortran directory to my Documents directory for source code.
Here is a simple "Hello World" program:

program helloworld
print *,"Hello World"
end program helloworld

Create the file in your favourite editor and save it into the directory.
In the terminal window, change the current directory to the saved location.
Compile using:
gfortran -o helloworld ./helloworld.f90
In the terminal enter the following:
./helloworld
The program will then print Hello World.

Using the Geany IDE

Geany is a default install on Raspbian, and makes it a lot easier to write programs than a simple text editor.
The application can be found by clicking on the Applications Menu/Programming/Geany Programming Editor.

Enter the program code (there is syntax highlighting once you have named the file with a suitable suffix, in this case: .f90 for Fortran 90).
To build and execute the program, click on Build/Execute. Geany will build then execute the code in a shell.



References
https://en.wikipedia.org/wiki/Fortran
https://gcc.gnu.org/fortran/
https://gcc.gnu.org/wiki/GFortran
https://en.wikipedia.org/wiki/IEEE-488
https://en.wikipedia.org/wiki/HP-150
https://en.wikipedia.org/wiki/Geany
https://geany.org/


Sunday, 1 July 2018

Arduino Installation on the Raspberry Pi

Though most software is available on the Raspberry Pi through the use of the APT repository, for some reason the version of the Arduino IDE is rather old, and possibly non standard.

To obtain the latest version you need to grab it from the Arduino web site here.

Follow the instructions and remember to choose the com port.