Notifications
Clear all

Problem uploading sketch.

125 Posts
6 Users
1 Likes
41.2 K Views
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

@zeferby

Hi Eric and Dorsay,

Hope everyone is safe and well, I am after a couple of months off Railway project trying to sort, know the last time I tried using my point servo sketch but after a while some of the DC90 servos seem to jam up and I was thinking its either because they are moving to fast or its because they are being kept live, and I know there is an Attach and Detach command that can be added to disable to servo's, and as the servo's are not under any tension so they cant spring back so this command would work fine.. but not sure how to add to sketch ..

Dorsay did you use the sketch that Eric posted and how did it work.

Regards John


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@john40131

Hi John !

Attach/Detach is for the basic Arduino Servo library, but don't apply to PCA9685 setups.  I'll look for a solution to have the PCA release a servo after setting it's position (but I'm not sure there's one...)

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 
Posted by: @zeferby

@john40131

Hi John !

Attach/Detach is for the basic Arduino Servo library, but don't apply to PCA9685 setups.  I'll look for a solution to have the PCA release a servo after setting it's position (but I'm not sure there's one...)

Hi Eric hope you are well, I found this on Arduino forum but like you say maybe it wont work with the PCA9685 ... its just on my sketch I think the problem is the servo's are moving to fast and thats what may be causing problem so is the sketch you did for Dorsay can a step be created so servo just moves more slowly so say the move prom position from 270 to 390 takes say 2 or 3 seconds instead of approx 0.5 seconds

The link on the discussion is ... https://forum.arduino.cc/index.php?topic=42232.0

Regards John

 


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

Hi Eric, some time ago you posted using the PCF8574 module and I was considering using this or the PCF8575 as a way of switching so I can get rid of the nasty minature toggle switches and use momentary minature push buttons for switching the points Arduino, if you you still have link would be gratful if you can re-post..

Regards John


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@john40131

Hi John, sorry I've been away a few weeks...

I found this sketch I had from last december, that uses a pair of PCF8574, using the IO Abstraction library from here : https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/

It may be a bit far from what you'll want to do, so don't hesitate to reach me for explanations or help.

 

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

Hi Eric, I tried using 595 shift registors as I saw a Youtube were someone had made a multiple operation keyboard but I couldnt get to work so I tried the one on the sketch, the sketch is long winded as I tried using arrays but failed miserable so this was the result it does work great and I was going to have to use a Mega to get 16 inputs and 16 outputs, although I could use the PCF8574 to extend the range of a Uno but not sure how to do this, the way I did this was to put an opto-isolator on the output of this Mega to feed into the polarity Mega so isolating the microcontrollers.. Using a Vishay CN74 which has 4 opto isolators onboard...

I am just about to try the servo program you did for Dorsay but concerned about the servo buzzing and or jamming as my original sketch caused me a few issue but did work...

Regards John

 


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@john40131

Hi John, first : if you want to go the array route, this sketch should be equivalent to yours :

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

This is the sketch with arrays ... it compilaed but didnt work..

 


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

@zeferby

Hi Eric just saw your reply, yes I will try that, can see a few errors I made ..


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@john40131

Ok, here is an example for 4x PCF8574, using the IOAbstraction library (Zip to be downloaded from https://github.com/davetcc/IoAbstraction ) :

Remember to check the I2C addresses of the 4 expanders

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

Hi Eric

Thanks very much that will be a big help, in the sketch there are 2 tabs one with the origanal sketch and one with the PCF8574 sketch, do I just need to use the new one also do I need to define the Button input and LED outputs or are they defined in this sketch..

Regards John


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
Posted by: @john40131

in the sketch there are 2 tabs one with the origanal sketch and one with the PCF8574 sketch

John, I think you want this new sketch to be in his own sub-directory in your sketch folder (give it the same name as the sketch), while you may have downloaded it into the folder for the original sketch ?

Posted by: @john40131

also do I need to define the Button input and LED outputs or are they defined in this sketch

They are defined at the end of setup() : basically you have a"flat" space of "abstract pins", the first 100 of them (0..99) are reserved for the physical pins of the Arduino, while you'll get ports 0..8 of the first PCF8574 as abstract pins 100..107, and so on for the following expanders.

Expanders A+B=switches, Expanders C+D=LEDs

  for (int i=0; i < NB_LEDS_BUTTONS; i++) {
ioDevicePinMode(multiIo, EXPANDER_C+i, OUTPUT); // LED i
ioDevicePinMode(multiIo, EXPANDER_A+i, INPUT_PULLUP); // button i (PULLUP for PCF8574)
switches.addSwitch(EXPANDER_A+i, onSwitchPressed); // switch management for button i
//You can also have a similar function if you wish to manage an event when a button is released
//switches.onRelease(EXPANDER_A+i, onSwitchReleased);
}

But remember to check the #define and the corresponding array initialization at the top of the sketch if you have less than 16x button+LED

Also : the buttons are in pull-up mode

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

Hi Eric..

I watched a video last night regarding the PCF8574 which was quite informative, and from that I can see that the output ithe opposite of a Arduino Uno etc as its is a pulldown were as the Uno/Mega is a pullup..

Also on your sketch which pins do I use for Inputs and Which for LED's I can see there are P0 .... P7 and Init at the end ..

I can see the programming is different to say a Uno/Mega ...

Also other boards are just connected to the IC2 bus and the Address is from 0x20 to 0x23 so 4 boards ...is the Init pin used in this operation... also can see there are diferent versions of the PCF8574 and "A" which I think can extend the number of boards also I think the 2 I have have a "T" at end so will have to check data sheet..

John


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@john40131

Hi John, those I have are basic ones from the french Amazon web site and their chips are marked PCF8574T. If you search PCF8574 on your amazon site, you should see quite a number of these, from multiple suppliers...

They have the 3 jumpers to choose between 8 possible I2C addresses, and the I2C pins (SDA/SCL/VCC/GND) are at both ends of the small board (1 set is male, 1 set female)

Then the I/O pins are P0-P7 for the 8 I/O ports, and the INT pin is for the board to signal an interrupt request to a micro controller, when any P0 to P7 port configured as input has a state change.

I don't use interrupts in the small script above, so INT is unused for this setup.

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
 

@zeferby

I also found this data sheet on the module which is helpful with setting address for each board..

https://protosupplies.com/product/pcf8574-i2c-i-o-expansion-module/

John


   
ReplyQuote
Page 7 / 9