Miletus brings Raspberry Pi target in Delphi
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. XCOPY deployment 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 New components 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 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)); SPI 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 […]
