RE: Creating a INA219 library for mikroC

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
cxshermansg
Posts: 13
Joined: 02 Feb 2018 14:49
Location: Singapore

RE: Creating a INA219 library for mikroC

#1 Post by cxshermansg » 10 Mar 2018 09:59

Hi guys, I am currently starting out on a project that I think might be able to lead somewhere purposeful some day. I have a project that requires me to think outside the box and to make use of various components from various makers/companies. In one of the portions of the project, I have worked up the need to interface a PIC18F26K20 with an INA219 breakout module by Adafruit.

As most of us are aware, the Adafruit INA219 has been created to be compatible with Arduino-supported development boards. So, I have been working with Arduino for a few years, knowing how to use the INA219 library has been like driving a car, I never had the reason or need to understand what happens underneath the hood when it comes to reading and writing those registers, reading values and so on.

But now, I have a need to build this custom integration between the PIC18F26K20 using mikroC and I am trying to crack my brains on how to establish the communication between the INA219 + my PIC on the EasyPIC v7. i am looking for any geeks or nerds who have a good idea how to adapt the INA219 library over to mikroC.

In the efforts of creating something like this, I intend to share the project within the "Examples" section of the mikroC environment as well. I like to contribute what I have learned and done with everyone within the community as well. I am pretty sure some people might find the application useful as well.

(Below) I am putting the library files side by side, hoping to figure out how to implement the read/writing of registers and getting the readings using I2C1_XX()
https://i.imgur.com/qvVfTwn.png <-- Sorry, high res image, so I attached as links

(Below) I am also going to put the library/code example under the Examples folder of mikroC.
https://i.imgur.com/ED0dqXz.png <-- Sorry, high res image, so I attached as links

Thanks again, I really appreciate it in advance, to anyone who can help me along. I have this weekend to figure this out.
cxshermansg
"I am always hacking at something, 24-7-265 days a year."/ "For some people, they have to be lucky all the time, but I only have to be lucky once." / "Keep trying and never give up until you succeed."

cxshermansg
Posts: 13
Joined: 02 Feb 2018 14:49
Location: Singapore

Re: Creating a INA219 library for mikroC (**NEW UPDATES**)

#2 Post by cxshermansg » 26 Mar 2018 18:49

Hey guys, so, a few weeks ago, I began working on the idea of integrating the Adafruit INA219 library to the mikroC development environment. I have been busy with a few other things lately but managed to test it out earlier tonight. I have used a video recording to document what has been done and also the values I have managed to retrieve from the INA219 breakout board. Base upon the video, you can see that I managed to retrieve the value of the current in mA. However, when trying to display it using the LCD, it seems to be in jibberish. I need to figure this portion out, so if anyone has any idea, I would really appreciate the help.

Here's the short 2 min 14 sec video I recorded using my phone:
https://drive.google.com/file/d/1c_kQkF ... sp=sharing
(Sorry if the video file seems quite large (332MB) and it seems to take a long time to upload. Maybe if the forum administrators take my UX feedback to add the progress indicator, it might just feel a lot faster.)

Here's the source code that I created using mikroC PRO for PIC:
INA219.zip
My source codes
(188.57 KiB) Downloaded 308 times
I might've figured out how to get the USB UART connector to work. I just had to change the switch SW1.1 (RC7) & SW2.1 (RC6). I have yet to test the UART, going to do that next.

I really need to figure out the returned values and how to properly filter/trim/process the values so I only get for example "3.20" for the mA, and when I print my string to the LCD, it should be just strings...not sure why it is always jibberish. What I like to display on the LCD is the following:

Code: Select all

Current: 3.20 (<-- only this value changes) mA
Not sure if this is possible. But I can also just print out the entire string again. (not that important)

Just to add to the UART portion of the program, I have been getting the following results:
UART-jibberish.jpg
UART-jibberish.jpg (115.06 KiB) Viewed 4026 times
cxshermansg
"I am always hacking at something, 24-7-265 days a year."/ "For some people, they have to be lucky all the time, but I only have to be lucky once." / "Keep trying and never give up until you succeed."

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: RE: Creating a INA219 library for mikroC

#3 Post by leo73 » 09 Mar 2020 15:04

hello Dear
I can't try INA219 library because i not have the right I2C library and follow functions:
void INA219_Init (void)
I2C1_Start();
I2C1_Wr(ina219_i2cAddress);
I2C1_Wr((value >> 8) & 0xFF);
I2C1_Wr(value & 0xFF);
I2C1_SetTimeoutCallback(1000,&test);
I2C1_Stop();

can you attach it (.h .c)in this discution please?
Thank you for your kind reply.

moein.firouzeh
Posts: 2
Joined: 20 Jul 2020 07:23

Re: RE: Creating a INA219 library for mikroC

#4 Post by moein.firouzeh » 20 Jul 2020 07:33

Hi every one , i have same problem by pic18f2550 . can any one help !
I need fresh and simple project create by pic18f2550 for reading ina219 sensor , that writed in mikroc.thanks :(

Post Reply

Return to “Library Development Discussion”