Recent

Author Topic: UnoLib - library in Pascal for Arduino Uno and ATMega328p  (Read 19289 times)

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #30 on: August 26, 2025, 06:24:03 pm »
UnoLib is now also on Reddit (https://www.reddit.com/r/unolib/), so I encourage you to discuss the library there as well. :)

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #31 on: September 18, 2025, 08:26:37 pm »
We have been at work on some significant improvements to the float32.pas unit. We have added the ability to use standard operators like +, -, *, and / directly with the TFloat32 type. We have attached the updated unit and its documentation for you to review, and any help with testing is welcome :)

Here is a sample test program for Arduino Uno

Code: Pascal  [Select][+][-]
  1. program TestFloat32;
  2.  
  3. {$IF NOT (DEFINED(atmega328p) or DEFINED(arduinouno) or DEFINED(arduinonano) or DEFINED(fpc_mcu_atmega328p) or DEFINED(fpc_mcu_arduinouno) or DEFINED(fpc_mcu_arduinonano))}
  4.  {$Fatal Invalid controller type, expected: atmega328p, arduinouno, or arduinonano}
  5. {$ENDIF}
  6.  
  7. {$mode ObjFPC}{H+}
  8. {$MODESWITCH ADVANCEDRECORDS}
  9.  
  10. uses
  11.         float32, hardwareserial, timer, stringutils;
  12.  
  13. var
  14.         StrA, StrB, StrC: string[32];
  15.         F32a, F32b, F32c: TFloat32;
  16.         i: UInt32;
  17. begin
  18.  
  19. //type your setup code here
  20.  
  21.         Serial.Start(9600);
  22.         Delay(1000);
  23.  
  24.         //program main loop
  25.         //type your code here
  26.         while true do
  27.         begin
  28.                 Serial.WriteLn('BEGIN TEST');
  29.                 Serial.Flush();
  30.  
  31.                 StrA := 'Hello ' + 'How '+ 'Are ' + 'You';
  32.                 Serial.WriteLn(StrA);
  33.                 Serial.Flush();
  34.  
  35.                 StrA := 'Very ' + 'Well '+ 'Thank ' + 'You';
  36.                 Serial.WriteLn(StrA);
  37.                 Serial.Flush();
  38.  
  39.                 StrA := '';
  40.                 F32a.RawData.Raw := $44201062; // 640.256
  41.                 StrA := F32a.ToString(3);
  42.                 Serial.Write('TFloat32 : $44201062 = 640.256  result: ' + StrA);
  43.                 Serial.Writeln('');
  44.                 Serial.Flush();
  45.  
  46.                 StrA := '';
  47.                 F32a.RawData.Raw := $40490FDB; // 3.14159
  48.                 StrA := F32a.ToString(5);
  49.                 Serial.Write('TFloat32 : $40490FDB = 3.14159  result: ' + StrA);
  50.                 Serial.Writeln('');
  51.                 Serial.Flush();
  52.  
  53.                 StrA := '';
  54.                 F32a.RawData.Raw := $3F49FBE7; // 0.789
  55.                 StrA := F32a.ToString(3);
  56.                 Serial.Write('TFloat32 : $3F49FBE7 = 0.789  result: ' + StrA);
  57.                 Serial.Writeln('');
  58.                 Serial.Flush();
  59.                 Serial.Flush();
  60.  
  61.                 StrA := '';
  62.                 F32a.RawData.Raw := $C2029DB2; // -32.654
  63.                 StrA := F32a.ToString(3);
  64.                 Serial.Write('TFloat32 : $C2029DB2 = -32.654  result: ' + StrA);
  65.                 Serial.Writeln('');
  66.                 Serial.Flush();
  67.  
  68.                 StrA := '';
  69.                 F32a := TFloat32.Create('789.123');
  70.                 StrA := F32a.ToString(3);
  71.                 Serial.Write('TFloat32.Create(''798.123'') result: ' + StrA);
  72.                 Serial.Writeln('');
  73.                 Serial.Flush();
  74.  
  75.                 StrA := '';
  76.                 F32b := TFloat32.Create('3.14159');
  77.                 F32c := Rad2DegFloat32(F32b);
  78.                 StrB := '';
  79.                 StrC := F32c.ToString(5);
  80.                 Serial.Write('Rad2DegFloat32(3.14159) result: ' + StrC);
  81.                 Serial.Writeln('');
  82.                 Serial.Flush();
  83.  
  84.                 StrC := '';
  85.                 F32b := TFloat32.Create('3.14159');
  86.                 F32c := SinFloat32(F32b);
  87.                 StrC := F32c.ToString(5);
  88.                 Serial.Write('SinFloat32(3.14159) result: ' + StrC);
  89.                 Serial.Writeln('');
  90.                 Serial.Flush();
  91.  
  92.                 StrC := '';
  93.                 F32b := TFloat32.Create('3.14159');
  94.                 F32c := CosFloat32(F32b);
  95.                 StrC := F32c.ToString(5);
  96.                 Serial.Write('CosFloat32(3.14159) result: ' + StrC);
  97.                 Serial.Writeln('');
  98.                 Serial.Flush();
  99.  
  100.                 StrA := '';
  101.                 StrB := '';
  102.                 StrC := '';
  103.                 F32a := TFloat32.Create('10.0');
  104.                 F32b := TFloat32.Create('21.0');
  105.  
  106.                 F32c := F32a + F32b;
  107.                 StrC := F32c.ToString(6);
  108.                 StrA := F32A.ToString(6);
  109.                 StrB := F32B.ToString(6);
  110.                 Serial.Write(StrA + ' + ' + StrB + ' = ' + StrC);
  111.                 Serial.Writeln('');
  112.                 Serial.Flush;
  113.  
  114.                 StrA := '';
  115.                 StrB := '';
  116.                 StrC := '';
  117.                 F32a := TFloat32.Create('125.0');
  118.                 F32b := TFloat32.Create('4.0');
  119.                 F32C := F32a mod F32b;
  120.                 StrC := F32c.ToString(6);
  121.                 StrA := F32A.ToString(6);
  122.                 StrB := F32B.ToString(6);
  123.                 Serial.Write(StrA + ' mod ' + StrB + ' = ' + StrC);
  124.                 Serial.Writeln('');
  125.                 Serial.Flush;
  126.  
  127.                 Serial.WriteLn('END TEST');
  128.                 Serial.Flush();
  129.                 Delay(1000);
  130.         end;
  131. end.
  132.  

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #32 on: November 11, 2025, 01:06:58 pm »
We have just released UnoLib 1.2 (https://sourceforge.net/projects/unolib/) featuring a new documentation overhaul aimed at making it easier to start using the library. The new How to Start guide offers two paths: a simple, automated setup via AVRPascal IDE or a manual configuration for advanced users (FPCUPdeluxe/Lazarus). We have updated the API for 13 modules, added clear connection diagrams to key examples, and included standard operators (+, -, *, /) for the TFloat32 type.

Changes:
- added the ability to use standard operators (+, -, *, /) directly with the TFloat32 type (by @Dzandaa)
- added new string conversion routines for TFloat32 (by @Dzandaa and @ackarwow)
- added new "docs" directory containing documentation (PDF files) for most library modules and the How to start guide for beginners
« Last Edit: November 11, 2025, 01:49:50 pm by ackarwow »

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #33 on: June 07, 2026, 02:16:15 pm »
UnoLib has received a small update. Changes include:
- optimized and extended StringUtils routines
- new SPI library unit based on the Arduino implementation
- ILI9163 TFT display example demonstrating SPI communication
The display example uses a 128×128 color TFT display connected to an Arduino Uno and renders the UnoLib logo from program memory using an indexed bitmap and palette.

Repository: https://github.com/ackarwow/unolib

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #34 on: June 23, 2026, 10:25:55 pm »
New version of UnoLib (1.3) has been released. Changes:
- added ArduinoISP.pas example (thanks to Christof Biner for the suggestion)
- added SPI support (spi.pas) and TestILI9163.pas example
- updated stringutils.pas and defs.pas
- made minor changes in fix16.pas

Download: https://sourceforge.net/projects/unolib/

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 762
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #35 on: June 24, 2026, 04:58:39 pm »
Thanks for the work!  Will be getting back to my 328p project in the next day or so, and will check it out!

ackarwow

  • Full Member
  • ***
  • Posts: 183
    • Andrzej Karwowski's Homepage
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #36 on: June 24, 2026, 11:47:28 pm »
Thanks for the work!  Will be getting back to my 328p project in the next day or so, and will check it out!

Thanks, Curt. Let me know how it works with your project. :)

cb_1964

  • Newbie
  • Posts: 4
Re: UnoLib - library in Pascal for Arduino Uno and ATMega328p
« Reply #37 on: June 27, 2026, 09:42:31 pm »
Thanks for ArduinoISP.pas, Great.

 

TinyPortal © 2005-2018