Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to control LED2 on PIC32 Pinguino-OTG?
23-12-2011, 04:16 PM,
#1
How to control LED2 on PIC32 Pinguino-OTG?
Being new to Pinguino, I am wondering how to control LED2 on the PIC32 Pinguino-OTG board using Pinguino/Arduino language. I understand how LED 1 (green) blinks but I don't know how to access LED2 (yelliow) which is on RD1 (pin49) and is not part of the Arduino platform. See attached schematic.

Lack of pinguino 32 bit language reference documentation (or not able to find it) is frustrating.
I appreciate any help.
Thanks
Bill


Attached Files
.pdf   PIC32-PINGUINO-OTG-schematic.pdf (Size: 76.46 KB / Downloads: 7)
Reply
24-12-2011, 01:29 PM, (This post was last modified: 24-12-2011, 04:22 PM by mf01.)
#2
RE: How to control LED2 on PIC32 Pinguino-OTG?
Hi Bill,

digtalw.c has been updated in r240 and const.h has been updated in r233 to specifically include LED2 for the PIC32 Pinguino-OTG board. You can either checkout the latest development release (r240) which also includes other changes or download the individual files digtalw.c and const.h from code.google.com/p/pinguino code.google.com/p/pinguino (open >trunk >p32 >include >pinguino >core under Directories on the left hand side of the screen if it is not already open)
and replace the existing files in //P32/include/pinguino/core.

Once you have the new digitalw.c and const.h files in your //P32/include/pinguino/core folder/directory you can use either (pin) 30 or LED2 in pinMode() and DigitalWrite() instead of LED1. You will probably have to close and restart the Pinguino IDE for the updated files to be used.

You can actually learn a lot about accessing additional features on the PIC32 Pinguino-OTG board by looking at the digitalw.c file. It is this file that provides the "mapping" between the "pin numbers", used by commands such as pinMode() and digitalWrite(), and the registers on the PIC32.

The translation is done by two arrays portmask[] and pinmask[].
In portmask[] 0=A, 1=B, 2=C, 3=D, 4=E, 5=F & 6=G.
In pinmask[] 0x01 = bit 0, 0x02 = bit 1, 0x04 = bit 2 etc.
By looking at element 30 of each array (noting that the first element is element 0) you can see that Pinguino Pin 30 is mapped to register RD1.

Whoops! In the r234 version of digtalw.c (which was the latest version when I originally posted this reply), element 30 of pinmask[] for both the PIC32 Pinguino and the PIC32 Pinguino-OTG should be 0x02, not 0x03. This did not stop LED2 working (I am currently using it in a test program with a PIC32 Pinguino OTG and LED2 is flashing away every 15 secs as I write this) but it did mean that pinMode() and digitalWrite() were trying to control two PIC32 registers at once, RD0 & RD1, and created a potential conflict between user button BUT and LED2. This was raised with the development team and corrected in r240 and this post updated.

LED2 is defined as (Pinguino pin) 30 in const.h (r233 and later).

NOTE that by "pin numbers" above, I mean the Pinguino platform pin numbers NOT the PIC32 IC pin numbers. The Pinguino IDE only "knows" about PIC32 registers and not the individual package pin numbers which vary between the various variants of the PIC32.

There is some language documentation in the pinguino wiki, but it is still very much working in progress.

I also am fairly new to the Pinguino but am gradually learning how to access the various facilities on the PIC32 Pinguino OTG board, which is how I learnt about the significance of the digitalw.c file.

Post updated to reflect re-issuing of digitalw.c in IDE r240.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
24-12-2011, 05:29 PM,
#3
RE: How to control LED2 on PIC32 Pinguino-OTG?
Thanks for the reply and information.
I noticed you said replace the existing files in //P32/include/pinguino/core.
I don't have P32/include/pinguino/core, I have P32/include/pinguino/basics which I presume you meant.

Also, how do I download the digitalw.c and const.h files from the site. I have a windows7 OS.

I also noticed that in the new digitalw.c that the pinmask for pin 30 and 31 are the same 0x02. Should they not be different?
Regards
Bill

Reply
24-12-2011, 06:07 PM, (This post was last modified: 25-12-2011, 12:59 PM by mf01.)
#4
RE: How to control LED2 on PIC32 Pinguino-OTG?
Hi Bill

(24-12-2011, 05:29 PM)magicman Wrote: Thanks for the reply and information.
I noticed you said replace the existing files in //P32/include/pinguino/core.
I don't have P32/include/pinguino/core, I have P32/include/pinguino/basics which I presume you meant.

Yes, you are correct. In release r206 or r208, which is probably what you are using, the folder was P32/include/pinguino/basics. It got renamed to P32/include/pinguino/core in r212.

(24-12-2011, 05:29 PM)magicman Wrote: Also, how do I download the digitalw.c and const.h files from the site. I have a windows7 OS.

Note: The following paragraph has updated information for downloading the individual files.

Follow the link in my earlier post and then click on the file name. This will take you to a window listing the file. On the right hand side of this window under "File info" is a link "View raw file". Right click on the "view raw file" link and a drop down menu should appear and select "Save link as..." (or that is what is says in Windows Vista - I don't have access to a Windows 7 system, but I suspect it is the same or something similar) and then choose where to save the file on your computer. I suggest keeping copies of the original const.h and digitalw.c files on your system before replacing them with the new versions just in case you have problems and need to revert to them.

(24-12-2011, 05:29 PM)magicman Wrote: I also noticed that in the new digitalw.c that the pinmask for pin 30 and 31 are the same 0x02. Should they not be different?
Regards
Bill

No because it is the combination of portmask[] and pinmask[] that identifies the register. Although in pinmask[] pin 30 and 31 are the same (0x02 = bit1), in portmask[] pin 30 is 3 (=D) and pin 31 is 5 (=F), so the corresponding register for pin 30 is RD1 and the corresponding register for pin 31 is RF1.

Hope that helps clarify the situation.

Mark

Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
25-12-2011, 10:14 AM,
#5
RE: How to control LED2 on PIC32 Pinguino-OTG?
Thanks for the info. When I did a save as link the file ended up with a lot of HTML in it causing massive errors. I opened the file with C++ studio and saved it which seemed to work OK...at least no complie errors.
However I still cant control LED2. LED2 never comes on. LED1 blinks OK


void setup() {
pinMode(13, OUTPUT);
pinMode(30, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set LED1 on
digitalWrite(30, LOW); // set LED2 off
delay(1000); // wait for a second
digitalWrite(30, HIGH); // set LED2 on
digitalWrite(13, LOW); // set LED1 off
delay(1000); // wait for a second
}

Any ideas?
Reply
25-12-2011, 11:58 AM,
#6
RE: How to control LED2 on PIC32 Pinguino-OTG?
Got it to work. I cut and paste the digitalw.c contents and then it worked OK. Somehow using the save link got the wrong file somehow. Anyway it works.


Reply
25-12-2011, 12:44 PM,
#7
RE: How to control LED2 on PIC32 Pinguino-OTG?
magicman,

apologies for that, I did not check the file downloaded. There is a way to download the individual file and I will amend my original post to give the corrected method.

Also, there has been a new windows version (r240) of the Pinguino IDE posted on the code.google.com/p/pinguiono site yesterday. It can be downloaded from Pinguino development release downloads. I have not tried the windows version but it should include many fixes including the updated digitalw.c and const.h files.

Glad you got it working in the end, despite my misleading advice.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
25-12-2011, 01:23 PM,
#8
RE: How to control LED2 on PIC32 Pinguino-OTG?
Thanks for all your help.
Reply
07-01-2013, 08:49 PM, (This post was last modified: 07-01-2013, 08:50 PM by Telboy.)
#9
RE: How to control LED2 on PIC32 Pinguino-OTG?
I know this is an old thread but I am new to the pinguino/arduino world - (I'm more of an assembler chap on old micros).

I am clearly missing the point here because I can not figure out the pin/port maps that make any sense.

trying to get a full list of what port is where and taking the example discussed previously :

[align=centre]
-------------------------------------------
In portmask[] 0=A, 1=B, 2=C, 3=D, 4=E, 5=F & 6=G.
In pinmask[] 0x01 = bit 0, 0x02 = bit 1, 0x04 = bit 2 etc.

By looking at element 30 of each array (noting that the first element is element 0) you can see that Pinguino Pin 30 is mapped to register RD1.
-------------------------------------------
[/align]

surely D0 is pin 30 and D1 is 31 - I know it isn't because the LED blinks on 30 but I do not understand the mapping.

I have looked at digitalW.c and conts.h and still none the wiser !

So if someone could point out what I am missing and then I could map the pins out so I can use them - currently I have the Omlimex PIC32-Pinguino-Micro.

Thanks in advance.
Reply
07-01-2013, 09:19 PM, (This post was last modified: 07-01-2013, 09:20 PM by pingotg.)
#10
RE: How to control LED2 on PIC32 Pinguino-OTG?
On mine I can use the name LED2 and it just works. No need to know it's 30 (or 31 or whatever).

It's actually defined in one of the H files (const.h) if you want to look at it.

Looks like you could use YELLOWLED instead if you prefer.

Both are set to 30. (But to other values for other boards that have the relevant LED on another pin.)

BTW, there's a great Xref PDF in the wiki that Mark made for the OTG but which applies to the Micro board too (at least mostly if not quite entirely).

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)