BlogAll Blog Posts | Next Post | Previous Post
Miletus brings Raspberry Pi target in DelphiBookmarks:
Monday, October 4, 2021
Last week, we showed a first glimpse in our lab where we demonstrated building a Raspberry Pi application from the Delphi IDE using Miletus. Today, we have a closer look at some of the new components as well as an extra video.
Creating a new Miletus Raspberry Pi app
From the IDE, simply select TMS WEB Miletus Application:
Now, in the project manager, under build targets, you see all the build targets Miletus offers. And there you have Raspberry Pi debug and release new targets.
With this Miletus project created and the Raspberry Pi target selected, you are ready to create your first Miletus application.
When you compile the Miletus for Raspberry Pi project from the Delphi IDE, you'll find the generated application and Raspberry Pi OS desktop shortcut link file in the output folder. Just XCOPY these 2 files to your Raspberry Pi with the Raspberry Pi OS and run the application. There is possibly just one extra step needed to prepare your Raspberry Pi to run the app and that is:
sudo apt install libwebkit2gtk-4.0-dev
While the entire array of TMS WEB Core components and TMS FNC Components is available to build a Miletus Raspberry Pi app, the Raspberry Pi target introduces three new components to access hardware attached to your Raspberry Pi SBC:
You see here:
TMiletusRaspberryI2C : read and write via the i²c ports to various sensors or other devices
TMiletusRaspberrySPI : read and write via the SPI port to various hardware extensions using the SPI port
TMiletusRaspberryUART : read and write from the UART to devices connected to the Raspberry Pi
I²C is a standard 2 wire protocol to communicate with devices. The Raspberry Pi offers out of the box two I²C interfaces. There is SCLK and SDA signal, i.e. the clock signal and the data signal that is open-collector based input / output. Communicating over I²C works via sending first an 8bit address and read or write bit over the SDA signal and then either write or read data bits. We exposed this in the TMiletusRaspberryI2C component via methods:
TMiletusRaspberryI2C.Open; TMiletusRaspberryI2C.Close; TMiletusRaspberryI2C.ReadByte(Address:byte): TJSPromise; TMiletusRaspberryI2C.ReadSmallInt(Address:byte): TJSPromise; TMiletusRaspberryI2C.ReadBuffer(Address:byte, Size: integer): TJSPromise;
Yes, you can see that the response of the read instruction is a promise as the read methods are asynchronous. Thanks to the promise based approach, we can still write sequential code to deal with reading and writing over I²C.
To write data, six methods exist
TMiletusRaspberryI2C.WriteByte(Address: byte; AData: byte); TMiletusRaspberryI2C.WriteByteP(Address: byte; AData: byte): TJSPromise; TMiletusRaspberryI2C1.WriteAddress(Address: byte); TMiletusRaspberryI2C1.WriteAddressP(Address: byte): TJSPromise; TMiletusRaspberryI2C1.WriteBuffer(AData: Array of byte; ASize: integer); TMiletusRaspberryI2C1.WriteBufferP(AData: Array of byte; ASize: integer): TJSPromise
As you can see, you can write a byte to some specific address or write an address followed by a buffer of data. The methods are all asynchronous and a promise based variant exists to allow to create sequential code.
This code snippet shows how to write two register values from an I²C device in a sequential way thanks to await()
ac1 := await(Integer, MiletusRaspberryI2C1.ReadSmallInt($AA)); ac2 := await(Integer, MiletusRaspberryI2C1.ReadSmallInt($AC));
The SPI protocol (Serial peripheral interface) uses a 3-wire connection, a clock and the data-in and data-out signal. Other than this, it is similar to I²C, meaning, it also uses an address and reads and writes data serialized over this 2 data wires.
The methods for the TMiletusRaspberrySPI component are:
TMiletusRaspberrySPI.Open; TMiletusRaspberrySPI.Close; TMiletusRaspberrySPI.ReadTransfer(var ABuffer: TBytes; AWSize: integer; ARSize: integer): TJSPromise; TMiletusRaspberrySPI.WriteTransfer(ABuffer: TBytes; AWSize: integer): TJSPromise;
Here you can see how a buffer of bytes is either read or written to the device connected to the Raspberry Pi over SPI.
Out of the box, the Raspberry Pi is also equipped with the good old serial port, or called UART. For serial communications, the baud rate, the bit count and parity can all be set via properties of TMiletusRaspberryUART. To read and write data, the TMiletusRaspberryUART offers methods:
MiletusRaspberryUART.Open; MiletusRaspberryUART.Close; MiletusRaspberryUART.ReadBuffer(var ABuffer: TBytes; ALength: integer): TJSPromise; MiletusRaspberryUART.WriteBuffer(ABuffer: TBytes; ALength: integer): TJSPromise;
Our colleague Holger Flick created a new video showing the steps to create a new Miletus Raspberry Pi app from the Delphi IDE to help you further when you get the beta in your hands:
We have the first beta build of Miletus with Raspberry Pi support available as part of TMS WEB Core v184.108.40.206. beta. Fwiw, Raspberry Pi won't be the only new target, in v220.127.116.11, you will also have macOS ARM support for the new Apple M1 CPUs. TMS ALL-ACCESS users can login on our website and under "My Products" in the TMS WEB Core section, download the new v18.104.22.168 beta of TMS WEB Core and start exploring.
And now of course, it is mainly our team that is not only extremely curious what kind of exciting applications you plan to make or have in mind but also very interested to hear how we can further enhance and extend this experience for you to create Raspberry Pi apps!
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post