• AVR Freaks

Helpful ReplyHot!Moving from Arduino to PIC

Author
bott
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/05/18 03:29:38
  • Location: 0
  • Status: offline
2018/05/22 01:09:55 (permalink)
5 (1)

Moving from Arduino to PIC

Hi all,
for the past 2 years one of the electrical engineers I work with has been designing control box around the ATMEGA2560. I cant really give away the full specification on here and hold on to my job but it does A LOT, loads of outputs, loads of inputs and about 8 different communication methods, datalogging to usb flashdrive, remote IoT monitoring, software fusing... its beautiful. we are working on a visual studio App for programming configuration files, looking in to mobile App development, had PCBs designed...any way he`s now leaving this business and this is getting dropped on to me as I have some experience with programming Arduinos for my own projects. The decision has been made to move to the PIC32MK1024GPD100, so i'm pretty much starting from scratch and seem to have found myself at the deep end. I can look at the code for the Arduino and it makes sense how everything is working, but poking around MPLAB, im as confused as a cow on Astroturf. I pretty sure that I have this wrong but I have found that in the Arduino IDE I can compile my Arduino code for Chipkit, and that in the MPLAB software i can import my Chipkit code. So i'm hoping that someone out there will simply say "yes its that simple, write in whatever language you like and the magic button will translate it to PIC, just figure out how to use that and you will be fine" however I suspect your going to say that I need to spend the next 6 years going over the code learning a new language watching my hair fall out. If so, then any pointers to help the transition from Arduino to PIC will be much appreciated.
 
Thanks 
           
#1
katela
Super Member
  • Total Posts : 1419
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: offline
Re: Moving from Arduino to PIC 2018/05/23 10:02:53 (permalink)
+2 (2)
Buy a good book and a PIC32 development board, few tutorials online and try to understand the datasheet.
It's different but not bad because you have some basic understanding of how microcotrollers work.

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#2
NKurzman
A Guy on the Net
  • Total Posts : 17918
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Moving from Arduino to PIC 2018/05/23 10:33:45 (permalink)
+2 (2)
You are moving from an 8 bit Arduino to a high 32bit PIC? You are not in the deep end, you are in a submarine.
Why the big change? Do you need the graphics? Ethernet?
What is your background?
Do you need right I/o timing? MIPS my not give it.
Do you just need more horse power.
The is a PIC32 aurduino addon by digalant
For straight PIC32 programming microchip offers C and C++.
You issue with aurdunio is not the language it is the libraries. You would need to port or write them.
#3
Mysil
Super Member
  • Total Posts : 3407
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: Moving from Arduino to PIC 2018/05/23 12:23:06 (permalink) ☄ Helpfulby ajinkya1149 2019/11/06 14:12:05
+2 (4)
Hi,
 
When making programs for Arduino, you essentially build everything on a set of libraries that is provided by the Arduino environment.
When you start with MPLAB X,  those libraries aren't there.
 
Arduino environment may run on a AT, or some PIC32MX... devices on a , even on a PIC32MZ2048EFG100 on aChipKIT Wi-Fire board.  As long as the sketches stay within the libraries, application code do not really need to know what processor is at the bottom.
 
Now, Source code for all Arduino libraries exist somewhere in the source code repository, for every microcontroller device that is able to run Arduino programs.
At some time, someone have made the libraries work on PIC32MX and PIC32MZ devices.
PIC32MX, PIC32MZ and PIC32MK are mostly very similar, when there are differences, those differences may be Big.
 
Microchip do not have a similar unified set of libraries.
There is Harmony, which is supported by development boards, and lots of example code, for PIC32MX, PIC32MZ, and PIC32MK devices.  It define it's own view of the world, and do not have any easily understood relation with the device Datasheet for the PIC device that is  used. And any library stuff provided by Harmony will be different from what you have been using.
 
It may work well if you can build from one of the development boards that have examples prepared, and modify from there, but othervise may have a pretty steep learning curve.
Making existing code that is developed in a different environment, to fit together with Harmony, may be a frustrating challenge.
 
Moving from ATMEGA2560  and what environment? Atmel Studio? or Arduino here also?
Moving to PIC32MK with MPLAB X seem like a big change.
 
 
Do you have a small piece of application code that you may publish, then maybe someone in this forum may take the challenge of showing how it can be done in a MPLAB project for PIC32.
But do not try with something that require a complete filesystem to support it.
 
   Mysil
 
#4
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11396
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Moving from Arduino to PIC 2018/05/23 13:08:09 (permalink)
+3 (3)
datalogging to usb flashdrive

 
But that ATMEGA doesn't have USB.
#5
NorthGuy
Super Member
  • Total Posts : 5735
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Moving from Arduino to PIC 2018/05/23 13:12:42 (permalink)
+3 (3)
If you have everything working very well, what's the need to switch to a different chip, yet alone the chip you don't know much about?
#6
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: Moving from Arduino to PIC 2018/05/24 14:32:14 (permalink)
+2 (2)
Hi,
Maybe the best solution would be to port your arduino software to the new arduino zero because it includes a SAMD21 (32bits) processor with USB device/host). It should be much easier to to migrate from an Arduino code using the exact same device.
Then you can use ATMEL studio and ASF
Regards
 
#7
Aussie Susan
Super Member
  • Total Posts : 3627
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: Moving from Arduino to PIC 2018/05/24 19:16:51 (permalink)
+5 (5)
The way I look at it, is that the Arduino has two basic functions: 'setup()' and 'loop()'.
If you take all of the code that is in the 'setup()' function and put it at the start of the 'main()' function then it will be executed once as well.
Then take all of the code from the 'loop()' function and put it in a 'while(1)' loop at the end of the 'main()' function and it will be executed over and over again.
That is probably patronisingly simplistic but it is the basis for what you need to go.
The next step is harder in that you need to convert all of the library calls into equivalent code that talks directly with the peripherals. For example, instead of using 'serial.begin(...)' you will need to write code that initialises the UART you want to use. For a device as simple as the UART, I prefer to interact directly with the various registers that are provided (read the data sheet and the appropriate Family Reference Manual (FRM) section for details and examples) but you may find that there are library functions that you can use. (Some many even suggest using the MCC but I have no experience in that and, going by the number of questions being asked, it may be a bit early in its development cycle.)
Interrupts should translate fairly easily in that Arduino calls a function to handle the interrupt and you (in effect) do the same when you write an Interrupt Service Routine (ISR).
However the bottom line is I recommend that you start at a very basic level. Get a 'flash a LED' program working and that will get you through the learning curve of how to handle the CONFIG settings, programming and debugging the code, configuring the oscillator etc..
From there you can add a function at a time and slowly build up the code that you need. I would never suggest that you try to translate the whole lot all at once.
Susan
#8
mfratus2001
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2009/02/23 01:35:33
  • Location: 0
  • Status: offline
Re: Moving from Arduino to PIC 2019/07/24 14:52:51 (permalink)
-1 (1)
I know the feeling of being the one to migrate. But, there is hope. Here is a tutorial:
https://circuitcellar.com/cc-blog/execute-open-source-arduino-code-in-a-pic-microcontroller-using-the-mplab-ide/
 
Let us know how it works out.
#9
ric
Super Member
  • Total Posts : 24217
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Moving from Arduino to PIC 2019/07/24 15:19:13 (permalink)
+1 (1)
After more than 12 months, I guess the OP has moved on...
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
PStechPaul
Super Member
  • Total Posts : 2431
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Moving from Arduino to PIC 2019/07/25 01:42:38 (permalink)
+1 (1)
Yes, with only the one post and no follow-up. The CircuitCellar article is 5 years old, and the Arduino library for the PIC32 is still available on http://kibacorp.com/free-downloads. I downloaded it and briefly looked at some of the source files. It might be useful, but probably needs to be modified for processors other than the PIC32MX250F128B.
 
I have a long-neglected project that uses the Arduino Pro Mini, that I think might be better done using a PIC and better programming and debugging tools than the FTDI USB/serial interface and Arduino environment. I might return to that project and one thing holding me back is choosing which processor and environment to use. The Arduino was chosen by someone else who had marketed this project (a DIY 10 kW EV battery charger) to be easily built and maintained by novices, but it was abandoned and I have two of them that I'd like to get working and possibly offer an upgrade kit for those who have problematic and non-working chargers. The original software (and hardware) were poorly designed and really not suitable for most DIYers, so the reason for the Arduino may no longer apply, and it is not that much more investment or mental effort to switch to a PIC and PICkit and the MPLABX and XCnn environment.

 
#11
lamdaelectronics
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2010/07/23 04:04:41
  • Location: 0
  • Status: offline
Re: Moving from Arduino to PIC 2019/07/25 03:30:17 (permalink)
0
The Import chipKIT Project (MPLABX: File>Import>Import chipKIT Project) can do the job without a hassle.
#12
PStechPaul
Super Member
  • Total Posts : 2431
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Moving from Arduino to PIC 2019/07/25 14:24:12 (permalink)
+1 (1)
I found the following for the ChipKit importer:
 
https://github.com/chipKIT32/chipKIT-importer
 
It says that the Arduino sketch should have been created in Arduino IDE using chipKIT-core in the Arduino Boards Manager. Perhaps I'll give it a try. The most daunting hurdle is the graphics library functions for the 1.8" TFT display, from Adafruit:
 
https://learn.adafruit.com/1-8-tft-display/graphics-library
 
I might also check out the Microchip graphics libraries, but it seems they are only for 16 and 32 bit processors. Perhaps it would be best to take that step, at least for this project. It is really not graphics-intensive, so an 8 bit device should be capable enough. The Arduino I'm using is an ATmega328P, which is 8 bit.

 
#13
lamdaelectronics
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2010/07/23 04:04:41
  • Location: 0
  • Status: offline
Re: Moving from Arduino to PIC 2019/07/26 01:44:11 (permalink)
0
Hi Paul,
if you wanna use the chipKIT plug in you have to use the MPLABX v.4.15! There were few errors using it with newer MPLABX versions. And it WORKS! you can use anything able to run on the chipKIT boards. I've done it with a 3.5" LCD. Mind you the result is in C++ (that's the language Arduino IDE is using). I didn't figure out why but if you try to run it in C++ the outcome is "extremely" SLOW. So, I turned the whole project to C.
Keep us informed on your project's progress.
post edited by lamdaelectronics - 2019/07/26 02:07:39
#14
Camerart
Starting Member
  • Total Posts : 45
  • Reward points : 0
  • Joined: 2013/04/12 02:19:40
  • Location: 0
  • Status: offline
Re: Moving from Arduino to PIC 2019/10/16 02:46:44 (permalink)
0
Hi,
I use PICs exclusively, mainly 18Series. I use Oshonsoft BASIC becaue it has a simulator, that I rely on.  I'm not a good programmer, and programs take me years where and expert may take a few weeks.
 
Best of wishes for transfering from Arduino, to PIC, I'll drop in occassionally to see if there's anything that I can follow.
 
It's a shame when an interesting thread is started, then the OP drops out.
Cheers, Camerart.
#15
Jump to:
© 2019 APG vNext Commercial Version 4.5