![]()
2. my note for pascalio with MCP23017 - 16 bit I/O expanding board.
2023.12.03 18:35
My note for pascalio/test/mcp23017_regaddress/project1.lpr file
{
I have connected one of the pin of PortA to one of the pin on PortB.
Therefore, when one pin from portA is "ON" as output,
the other pin from PortB should be "ON" for input.
}
program project1;
{$mode objfpc}{$H+}
uses
sysutils,
pascalio, fpi2c, mcp23017
{ you can add units after this };
var
idev: TI2CLinuxDevice;
mcp: TMCP23017Controller;
bval, b: Byte;
begin
idev := nil;
mcp := nil;
try
idev := TI2CLinuxDevice.Create($20, 1); // for /dev/i2c-1, address $20
writeln('Device file handle: ', idev.Handle);
mcp := TMCP23017Controller.Create(idev, True);
b := mcp.GPIOA;
Writeln('Register GPIOA: ', binstr(b,8));
mcp.IODIRB := $00; // GPIOB = Output
for bval := 0 to 5 do
begin
mcp.GPIOB := $FF;
b := mcp.GPIOA;
Writeln('Register GPIOA: ', binstr(b,8));
Sleep(1000);
mcp.GPIOB := $00;
b := mcp.GPIOA;
Writeln('Register GPIOA: ', binstr(b,8));
Sleep(1000);
end;
except
// this exception handling should be a try/finally block
// but FPC 2.7.1 doesn't do the default exception handling
// so this is workaround to avoid memory leaking the exception object
on e: exception do // Error Handling
begin
writeln(ErrOutput, 'E Class : ', e.ClassName);
writeln(ErrOutput, 'E Message: ', e.Message);
writeln(ErrOutput, 'E Address: ', hexStr(ExceptAddr));
end;
end;
mcp.Free;
end.


Comment 0
| No. | Subject | Author | Date | Views |
|---|---|---|---|---|
| 14 |
i2c ADC 4 channel (ADS1115)
| me | 2023.12.20 | 621 |
| 13 |
Ultrasonic with free pascal
| me | 2023.12.05 | 424 |
| 12 |
Trigger Test with pascalio
| me | 2023.12.04 | 370 |
| 11 |
3. my note for pascalio with MCP23017 - 16 bit I/O expanding board.
| me | 2023.12.03 | 707 |
| » |
2. my note for pascalio with MCP23017 - 16 bit I/O expanding board.
| me | 2023.12.03 | 700 |
| 9 |
Bitwise Operation in Object Pascal
| me | 2023.11.25 | 485 |
| 8 |
Making BNO-055 Library for Linux SBC in Object Pascal
[1] | me | 2023.11.22 | 850 |
| 7 |
Nano Seconds Control : Failed, but micro seconds levels worked.
| me | 2023.11.22 | 708 |
| 6 |
1. my note for pascalio with MCP23017 - 16 bit I/O expanding board.
| me | 2023.11.20 | 728 |
| 5 |
pascalio on Orange Pi 5 for I2C control
| me | 2023.11.20 | 759 |
| 4 |
Working UDP between Orange Pi 5 <=> PC
| me | 2023.09.29 | 460 |
| 3 | Simple UDP Sensor Server in Python <=> Object Pascal [1] | me | 2023.09.27 | 530 |
| 2 |
Simple Joystick with SdpoJoystick Component on Linux
| me | 2023.09.22 | 324 |
| 1 |
Virtual Lidar for test
[1] | me | 2023.07.20 | 552 |