Recent

Author Topic: FPC/Lazarus Arduino Tutorial  (Read 41300 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: FPC/Lazarus Arduino Tutorial
« Reply #15 on: January 31, 2016, 09:06:35 pm »
.. it off for years. But, given that I am 76 and retired there seemed no real point. Now that I am messing with Arduino, the point has become obvious.
We can't have you switch to c(++), really there is no point especially at such respectable age :-)

Quote
I saw the mention of "trunks" ...
Every FPC/Lazarus you can download from official link and install is a release (whether it is a beta, a release candidate or otherwise).

with trunk is meant, the very up to date sources that are stored on the svn/git server. Every time a developer makes a change/improvement/otherwise to the FPC sources, the developer 'uploads' his local stored changes to the svn/git server. Git/svn is version control, consisting of tools that allows multiple developers to work at same source-tree and doing so at the same time (such as in FPC's/Lazarus' case).

Quote
...if a large chunk of the instructions assumes I am an expert on Lazarus and the things needed to create a cross-compiler with it. By definition a Tutorial should be for the lowest common denominator.
Although i understand that from end-user perspective, it is assumed that when using trunk that you know what you are doing.

A 'tutorial' on how to build the experimental compiler from trunk for avr, was/is actually written here.

Quote
Now, I am not by any stretch expecting that degree of detail on a free website, but I do expect tutorials to be just that. If a "trunk" version is need then a link to that download is mandatory.
I think that was/is a small oversight in that the person writing the tutorial assumed that you understand where to 'fetch' trunk sources.

It was not my intention to grieve you in any way with my quitter remark... actually i was trying to encourage you to try again and report further 'errors' or 'incomprehensible' instructions -> that is the only way able to let things improve.


Thanks to engkin, he wrote very detailed instructions that should work for you. (i was actually starting to write something similar, based on your return answer).

@engkin:
thank you very much.

edit: typo's
« Last Edit: January 31, 2016, 09:09:57 pm by molly »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2325
Re: FPC/Lazarus Arduino Tutorial
« Reply #16 on: January 31, 2016, 09:22:53 pm »

Hint:

 "arduino-using-lazarus-free-pascal"

https://bigdanzblog.wordpress.com/full-list-of-posts/







Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #17 on: January 31, 2016, 11:00:57 pm »
Thanks Molly, I understood the light heart-ed "quitter," it's all good.

I basically understood what  trunk meant but could not find it anywhere. Even searching with google returned no links to trunk downloads and that's why I reverted to the current stable. When you know where to look it is simple.

it is assumed that when using trunk that you know what you are doing.

haaa, ha. :) If I couldn't find a trunk how would I know what to do?

Thanks to engkin, he wrote very detailed instructions that should work for you. (i was actually starting to write something similar, based on your return answer).

I appreciate the efforts of both of you. There is a typo in the link to the FPC
http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

should be...
ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

I knew enough to figure that out. Stuff downloading as I type.

I had seen the wiki page but the opening sentence
Quote
The FPC-AVR port is currently experimental and non working.
Was too ominous to bother with trying.

p.s.
I had also found big Dan's site but I am already happy with the Delphi code I have written that uses the Serial ports to communicate both ways with the Arduino boards. I went looking for this Lazarus/AVR solution as my skills with the Arduino C/C++ were hitting a technical wall. I  was fine with the basic programming, but am now running out of skill for the more advanced stuff I need the Arduino to do.
« Last Edit: January 31, 2016, 11:11:42 pm by HatForCat »
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPC/Lazarus Arduino Tutorial
« Reply #18 on: January 31, 2016, 11:21:19 pm »
Hint:

 "arduino-using-lazarus-free-pascal"

https://bigdanzblog.wordpress.com/full-list-of-posts/

Nice link, thank you!

@engkin:
thank you very much.

You are welcome, although I did nothing. It is ykot, you & HatForCat that motivated the effort to write that post.

There is a typo in the link to the FPC
http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

should be...
ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip

Thanks for pointing that out. I just corrected it. It seems that "Insert Hyperlink" button does not like ftp protocol.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #19 on: January 31, 2016, 11:37:01 pm »
For Windows:
3-Decompress that archive somewhere (if you did that in c:\avrtest then you should have a file named make in c:\avrtest\fpc\ folder )

Thanks, I appreciate the help, but hit a snag, no Make, but I have 7 Folders and
Code: [Select]
avrbuild.bat <<- saved as per instructions. used all recommended Folders/Paths
fpmake.pp
fpmake_add1.inc
fpmake_proc1.inc
Makefile
makefile.fpc
readme.rev

Running avrbuild.bat
Code: [Select]
C:\avrtest\fpc>avrbuild

C:\avrtest\fpc>REM if you installed Lazarus 1.6 RC2 in c:\Laz1.6RC2 it comes wit
h FPC.exe in c:\Laz1.6RC2\3.0.0\bin\i386-win32 folder

C:\avrtest\fpc>REM That is the folder we need to add here.

C:\avrtest\fpc>SET FPC_PATH=c:\Laz1.6RC2\3.0.0\bin\i386-win32

C:\avrtest\fpc>REM The compiler itself ( Which its location is saved in FPC_PATH
 )

C:\avrtest\fpc>SET PPCBIN=c:\Laz1.6RC2\3.0.0\bin\i386-win32\fpc.exe

C:\avrtest\fpc>REM A folder where the generated cross compiler and run-time libr
aries are going to be saved

C:\avrtest\fpc>SET INSTALL_PATH=c:\avrtest\Win32

C:\avrtest\fpc>REM We need the path to avr-embedded-* files

C:\avrtest\fpc>SET NDK_BIN=c:\avrtest\

C:\avrtest\fpc>REM Make all the binary files that we need accessible

C:\avrtest\fpc>SET PATH=c:\Laz1.6RC2\3.0.0\bin\i386-win32;c:\avrtest\;C:\Windows
\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerSh
ell\v1.0\;

C:\avrtest\fpc>REM Start the process

C:\avrtest\fpc>make clean crossall crossinstall FPC=c:\Laz1.6RC2\3.0.0\bin\i386-
win32\fpc.exe OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=c:\a
vrtest\Win32 CROSSBINDIR= BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
'make' is not recognized as an internal or external command,
operable program or batch file.

C:\avrtest\fpc>
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPC/Lazarus Arduino Tutorial
« Reply #20 on: February 01, 2016, 12:07:36 am »
For Windows:
3-Decompress that archive somewhere (if you did that in c:\avrtest then you should have a file named make in c:\avrtest\fpc\ folder )

Thanks, I appreciate the help, but hit a snag, no Make, but I have 7 Folders and

You are right, it is called Makefile. Corrected the post, thanks!

Quote
C:\avrtest\fpc>make clean crossall crossinstall FPC=c:\Laz1.6RC2\3.0.0\bin\i386-
win32\fpc.exe OS_TARGET=embedded CPU_TARGET=avr SUBARCH=avr5 INSTALL_PREFIX=c:\a
vrtest\Win32 CROSSBINDIR= BINUTILSPREFIX=avr-embedded- CROSSOPT="-O3 -XX -CX"
'make' is not recognized as an internal or external command,
operable program or batch file.

I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe? If not something went wrong with your installation. I installed that version of Lazarus and I have that file there.
« Last Edit: February 01, 2016, 12:09:19 am by engkin »

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #21 on: February 01, 2016, 12:22:38 am »
I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe?

Thanks for the follow up. That path is not what I have, but make.exe is here...
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

I changed the batch file and it is doing stuff? It skipped all but two of the avr-embedded... files. Is that good?

"Duty" calls again and must close down for the night. I will report back in the morning.

Thanks again for the help.



Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPC/Lazarus Arduino Tutorial
« Reply #22 on: February 01, 2016, 12:41:42 am »
I assume you did install Lazarus 1.6 RC2, check in your Lazarus folder c:\Laz1.6RC2\3.0.0\bin\i386-win32\ do you see a file named make.exe?

Thanks for the follow up. That path is not what I have, but make.exe is here...
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

I have to admit, I cheated, I'm working on a different computer than this one. You have the correct path. I just modified the post above to reflect this correction. Thank you.

I changed the batch file and it is doing stuff? It skipped all but two of the avr-embedded... files. Is that good?

We both will know the answer when you check the c:\avrtest\Win32 folder.

herux

  • Full Member
  • ***
  • Posts: 102
Re: FPC/Lazarus Arduino Tutorial
« Reply #23 on: February 01, 2016, 02:52:47 am »
I love this thread, will try it later. I will buy arduino first of course  :D

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #24 on: February 01, 2016, 04:56:16 pm »
I love this thread, will try it later. I will buy arduino first of course

:D Don't be too hasty, I have not found out how to use it yet.

I opened the IDE and went through every option, operational-function, plug-in and anything thing else. Nothing mentions compiling for Arduino. I may be ruing the moment and now heeding that ominous warning from engkin, "How to use them is a different story."

@engkin:
Quote from: engkin
If it succeeded then you should have:
1-a cross compiler named ppcrossavr.exe in c:\avrtest\win32\bin\i386-win32
2-compiled rtl units in c:\avrtest\units\avr-embedded\

I do indeed have
ppcrossavr.exe
C:\avrtest\Win32\bin\i386-win32
and
173 items in
C:\avrtest\Win32\units\avr-embedded\rtl

Am I correct in now assuming that there are no further instructions? :) I had assumed that after all of this, upon launching the IDE, I would simply select a Platform to compile to. Once done, I then use the AVRDude instructions from the OP. But, it seems we are still a long way from integrated at this point.

Shaking and shuddering, I see C/C++ looming on my horizons. I am grateful for the help getting thus far, but as you warned, "How to use them is a different story."

It seems ironic that now that I have achieved that ppcrossavr.exe status, I am now left to my own devices. I shall charge ahead as nothing ventured, nothing gained. What's the worst that could happen? I have full daily image backups, I, well, my laptop is invincible. {gasp!!}
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

Leledumbo

  • Hero Member
  • *****
  • Posts: 8786
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC/Lazarus Arduino Tutorial
« Reply #25 on: February 01, 2016, 05:27:49 pm »
For anyone interested, here is the Help page from the cross compiler { SHOCK HORROR }
That's just the generic -h output, fpc -i should show architecture specific information.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPC/Lazarus Arduino Tutorial
« Reply #26 on: February 01, 2016, 05:43:35 pm »
I love this thread, will try it later. I will buy arduino first of course

:D Don't be too hasty, I have not found out how to use it yet.

I opened the IDE and went through every option, operational-function, plug-in and anything thing else. Nothing mentions compiling for Arduino. I may be ruing the moment and now heeding that ominous warning from engkin, "How to use them is a different story."

1-Copy (I actually moved it) avr-embedded folder (located in c:\avrtest\win32\units\) to:
c:\Laz1.6RC2\fpc\3.0.0\units\ folder
( In this folder there is already a folder named i386-win32 )

2-Copy ppcrossavr.exe to its normal location among FPC binaries, that is to:
c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\

3-While you are still in c:\Laz1.6RC2\fpc\3.0.0\bin\i386-win32\ folder, there is a file named fpc.cfg.

a-Open the fpc.cfg with your preferred editor ( I dropped it on Lazarus )

b-Go to the end of the file.

c-Add the following ten lines to it ( to guide FPC where/how to find avr-embedded-* files, and a few more options ):
Code: Pascal  [Select][+][-]
  1. #ifdef embedded
  2. -FDc:\avrtest\
  3. -OoFastMath
  4. #-XX
  5. -CX
  6. -Oonostackframe
  7. #ifdef avr
  8. -XPavr-embedded-
  9. #endif
  10. #endif

d-Save it and close it.

If you did all of that then download the sample app attached to ykoy's first post.

Unpack it (I did that in c:\avrtest folder and I ended up with the sample project inside c:\avrtest\Blinky folder).
Open the project, and compile.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #27 on: February 02, 2016, 12:32:31 am »
Open the project, and compile.

You are more than aptly named "Hero Member," we just got back from shopping, but "duty" again calls so I will tackle this in the morning.

Thank you so much for all the time and effort. Greatly appreciated.
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

herux

  • Full Member
  • ***
  • Posts: 102
Re: FPC/Lazarus Arduino Tutorial
« Reply #28 on: February 02, 2016, 03:47:21 am »
Quote
:D Don't be too hasty, I have not found out how to use it yet.

Not reckless, too, we can try and maybe could help development.  ;)

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: FPC/Lazarus Arduino Tutorial
« Reply #29 on: February 02, 2016, 07:08:47 pm »
Open the project, and compile.

Excellent. It created the blinky.hex

Next issue is avrdude. With the OPs instruction I got some errors and here's what I have done so far. The green bits are where I have installed the Arduino stuff, so, others will need to swap in their own for their installation. Most likely "c:\program Files\Arduino" at a guess.

The Path to avrdude within the Arduino installation folders needs to be added to the Windows Path.
D:\_Programs\_ArduinoIDE\hardware\tools\avr\bin

Also, the configuration file for avrdude needs to be included in the OP's instructions and some extra items added to the command. Please note that command line switchs for avrdude ARE case-sensitive.
D:\_Programs\_ArduinoIDE\hardware\tools\avr\etc\avrdude.conf

Here is the contents of a batch file, but so far it only uploads to a Uno and not a Nano or Mega. With the Nano/Mega avrdude hangs and then fails after 10 tries with a ten of these errors.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x53

I saved the batch file as "test.bat" in the same folder as blinky.hex and launched within a Command Prompt with "test com5 blinky.hex" (without quotes) and it has the Uno blinking on com port 5.
Code: [Select]
avrdude -CD:\_Programs\_ArduinoIDE\hardware\tools\avr\etc\avrdude.conf -v -patmega328p -carduino -P\\.\%1 -b115200 -D -Uflash:w:%2:i

Good news is the failed Nano/Mega uploads did no damage to the boot-loader in the Nano or Mega as they still upload OK from the Arduino IDE.

I also tried to create an External Tool within the Lazarus IDE to launch that batch file, but cannot seem to make it work.
Things still to fix.
1: Assign the various boards for avrdude to work with Nano, Mega etc.
2: Create a working External  Tool with in the Lazarus IDE to launch the batch file.

It's getting closer. :)

Thanks for everyone's help so far.

p.s.
I have blocked C/C++ tutorial sites from my browser. ;)

« Last Edit: February 02, 2016, 07:12:12 pm by HatForCat »
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

 

TinyPortal © 2005-2018