CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Nov 20, 2018 11:08 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 19 posts ]  Go to page 1 2 Next
Author Message
PostPosted: Wed Apr 02, 2014 12:41 pm 
Offline

Joined: Tue Feb 18, 2014 10:46 am
Posts: 13
To the good people of the CODESYS forum,

I've been developing a system with the new release of the Raspberry Pi platform. What's great about the GPIO access is you can have various other devices running on a "C" program and if any of you are familiar with the WiringPi libraries (found here), then you can actually "pulse a GPIO" upon a program condition, this way the codesys application can then register a change and drive other sub-systems (say a WAGO connected on the Pi's Ethernet).
It's brilliant!

The final sub-system I need to connect is a current sensor through I2C. I have the INA219 board, bought from here).

I've attached my feeble attempt at writing the driver from scratch, basing it on the Adafruit_I2C_PWM library.
The software recognizes the I2C setup, but I don't believe it "properly" connects to the device let alone control it at the current state it's been written in.


Image

If anyone can aid me in my struggle I would be immensely grateful.

-Hodgy.

_____________________________________________________________________________________________________________

INA219 Current Sensor Datasheet: http://www.adafruit.com/datasheets/ina219.pdf


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Apr 03, 2014 8:43 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
Hi Hodgy

Unfortunately we do not have the device here to test it.
But looking into your library, I can see that the default i²c address (that is used if you do not set the address in the device configuration (parameters)) is 0x41 (see body of Adafruit_CurrentSense, line 6). Did you verify this with i2cdetect?

What I saw in the Adafruit example code is that the registers are 16bit long:

Code:
  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
                    INA219_CONFIG_GAIN_8_320MV |
                    INA219_CONFIG_BADCRES_12BIT |
                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
  wireWriteRegister(INA219_REG_CONFIG, config);

In your lib you used the write8 method.

Currently, there is no ready-to-use write16 method, but it is easy to program in your own lib:
Code:
METHOD write16 : BOOL
VAR_INPUT
      usiRegister: USINT; (* register to write *)
      uiValue: UINT; (* value *)
END_VAR
VAR
      Buffer:  ARRAY[0..2] OF BYTE;
END_VAR
---
Buffer[0] := usiRegister;
Buffer[1] := UINT_TO_USINT(SHR(uiValue, 8));
Buffer[2] := UINT_TO_USINT(uiValue AND 16#FF);
Write16 := DINT_TO_BOOL(Write(ADR(Buffer), 3));

I guess that this should solve the problem!

Instead of the BeforeWriteOutputs method you should use the AfterReadInputs method, as this device is an input device. You can compare to the SRF02, which is also a pure sensor which is similar to yours

"c:\Users\<Username>\CODESYS Control for Raspberry PI\1.1.0.0\I2C_SRF02.library"

BR
Edwin


Top
   
PostPosted: Mon May 26, 2014 4:46 pm 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
How to install this

Quote:
Adafruit CurrentSense Library.library [339.17 KiB]
Adafruit CurrentSense.xml [2.51 KiB]


libraries into system to actualy get this device working ?


Top
   
PostPosted: Mon May 26, 2014 5:50 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
Hi,
what exactly does not work, the install process to the repositories or adding the device and library and use them?
we need more information.

BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Mon May 26, 2014 9:56 pm 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
I'd like to know when I have .library and .xml how to install it into codesys. In this case I mean about those two libraries. I had download it from forum, but did0t know what to do with it :(.


Top
   
PostPosted: Tue May 27, 2014 4:33 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
Hi,
the procedure is:
install the library by Tools-> Install Library
this install the library to the library repository

install the device by Tools-> Install device
this install the device to the device repository

BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue May 27, 2014 8:41 am 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
Great! That's clear.

I'm starting to develop library based on PiFace. I'm not sure I'll succeed so easy, so how to deinstall device and library from system?

BR,

Mladen


Top
   
PostPosted: Tue May 27, 2014 2:58 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
Hi,

important point is for library development you need to switch to professional mode
under Tools-Features. (see screenshot)
If you use CODESYS in "Standard" User mode you could not even save the library.

best practice for library development is:
Open two instances of CODESYS
one instance 1 of CODESYS -> open the library which you want to develop (open for example d:\I2C.library)
second instance 2 of CODESYS -> open th project which you could test your library. (open for example d:\Testproject.project)

(Also debugging in the project (this is instance 1) in the library is possible... by setting brakepoint in the library fb's)

If you change some implementation on Library use the yellow symbol to update the library in the library repository
the second instance of CODESYS recognize the change and you need to download the changes and could retest the new changes.


BR
Edwin


You do not have the required permissions to view the files attached to this post.


Last edited by Edwin Schwellinger on Wed May 28, 2014 3:24 pm, edited 2 times in total.

Top
   
PostPosted: Wed May 28, 2014 11:07 am 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
Hi!

Idea about using two IDE for library development is great. Library and device should be installed first and import device/library into new project, am I right ? In this scenario then I have to open library from "C:\ProgramData\CODESYS\Managed Libraries\VendorName\...." ?

BR,

Mladen


Top
   
PostPosted: Wed May 28, 2014 11:08 am 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
I presume to remove device and library from system is enough to delete folders e.g. "0000 0003" from "C:\ProgramData\CODESYS\Devices\501" and "Raspberry SPI PiFace" from C:\ProgramData\CODESYS\Managed Libraries\3S - Smart Software Solutions GmbH\" ?


Top
   
PostPosted: Wed May 28, 2014 2:13 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
>I presume to remove device and library from system is enough to delete folders e.g. "0000 0003" >from "C:\ProgramData\CODESYS\Devices\501" and "Raspberry SPI PiFace" from C:\ProgramData\CODESYS\Managed Libraries\3S >- Smart Software Solutions GmbH\" ?

Would not recommend to open them from the repository location, you need to copy them to d:\ (somewhere on your harddisk) open it from there
and install it later by CODESYS to the repositories (same for Devices).

BR Edwin


Top
   
PostPosted: Wed May 28, 2014 2:29 pm 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
Edwin,

I asked about how to delete library and device :)
Quote:
I presume to remove device and library from system is enough to delete folders e.g. "0000 0003" >from "C:\ProgramData\CODESYS\Devices\501" and "Raspberry SPI PiFace" from C:\ProgramData\CODESYS\Managed Libraries\3S >- Smart Software Solutions GmbH\" ?


Top
   
PostPosted: Wed May 28, 2014 2:36 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2962
delete devices here:
and delete libraries here:

Altough I do not know why you want delete them...

BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Wed May 28, 2014 2:41 pm 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
Quote:
Would not recommend to open them from the repository location, you need to copy them to d:\ (somewhere on your harddisk) open it from there
and install it later by CODESYS to the repositories (same for Devices).

Hmmm :?:

Please can you explain how to open same library in two IDE? First is developing and library is on temporaly folder, and second is testing IDE.

BR,

Mladen


Top
   
PostPosted: Wed May 28, 2014 2:42 pm 
Offline

Joined: Wed Feb 26, 2014 5:48 am
Posts: 52
Quote:
Altough I do not know why you want delete them...


When I make some seriuos error while developing new device/library :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 19 posts ]  Go to page 1 2 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited