# Changing SDA Pin mode in software

**URL:** https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213
**Category:** Motor controllers/drivers and motors
**Created:** [November 27, 2024, 12:58pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213 "2024-11-27T12:58:11Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [November 27, 2024, 12:58pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/1 "2024-11-27T12:58:11Z")

</div>

Hi. I’m using a TIC 36v4 to control a stepper motor that drives my dome around. I use the limit switch reverse function on SDA to allow the dome to find Home. The snag arrives if I want to travel beyond the switch position as of course a dome can continuously rotate. So I decided I could maybe use the set\_sda\_pin\_mode function to turn SDA off as a limit switch after the homing had been done and turn it back on as a limit switch when I need it for homing. I only use the home function at most once per evening viewing, and often not even then !  
However try as I might I cannot get this switching to actually happen. I’m verifying the pin status by using the Pololu Tic control center having run code to change the pin mode. The pin mode never changes. I’ve also tried using

bool v = m\_tic.set\_setting\_byte(61, 9);  
to set it as a limit switch and then

bool v = m\_tic.set\_setting\_byte(61, 2);  
to disable the limit switch

and again nothing changes when I check in the control center. I’m using C# in Microsoft Visual Studio

Any suggestions  
Thanks  
Tim

---

<div class="post-metadata">

### Author: ![BrandonM](https://forum.pololu.com/user_avatar/forum.pololu.com/brandonm/32/609_2.png) [@BrandonM](https://forum.pololu.com/u/BrandonM)
#### Post date: [November 27, 2024, 11:42pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/2 "2024-11-27T23:42:18Z")

</div>

Hello, Tim.

It looks like you’re trying to use an offset of 61 (which is 0X3D in hex); please note that this is the offset value for the TX pin configuration. For the SDA pin configuration, you should be using an offset of 60 (0x3C in hex).

Are you using a C# library for the Tic, and if so, could you link to it? Alternatively, could you post the code for your `set_setting_byte()` function?

Brandon

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [November 29, 2024, 9:38am UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/3 "2024-11-29T09:38:14Z")

</div>

Hi Brandon

Thank you for the response

My mistake, in the actual code I did use the correct address. This was a test to see if I could change any of the pins modes, which I couldn’t

Yes I am using the C# library for the TIC. I tried using the method to directly change the SDA pin but that didn’t work either and actually returned “false”.

Regards

Tim

---

<div class="post-metadata">

### Author: ![BrandonM](https://forum.pololu.com/user_avatar/forum.pololu.com/brandonm/32/609_2.png) [@BrandonM](https://forum.pololu.com/u/BrandonM)
#### Post date: [November 29, 2024, 10:26pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/4 "2024-11-29T22:26:18Z")

</div>

Can you post a link to the C# library you’re using?

Brandon

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 5, 2024, 5:05pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/5 "2024-12-05T17:05:07Z")

</div>

Hi Brandon  
I’m using the TicDotNet library from here [GitHub - jigarciacortazar/TicDotNet: .NET access to Pololu TIC stepper controllers Written in C #](https://github.com/jigarciacortazar/TicDotNet)

A line of code that uses the set\_sda\_pin\_mode function to change the mode to “Limit switch forward” or “Limit switch reverse” would be very welcome, with another to set the pin back to some other value when it’s not homing. The pin also needs to be set to high as the switch closes when it senses the home position.  
Whenever I call this function it returns “false” so I’m clearly doing something wrong. I’m using C# in Visual Studio Code 2022.

Other than that my Astronomy Dome software works a treat under the ASCOM protocol. What I wish to do is have the limit switches only active when I am homing, not when I’m slewing. If active when slewing they prevent the dome from passing through the home position. The home position is used to ensure the dome is synced precisely to north so it accurately follows the telescope as it slews.

Thank you for any help you can offer  
Tim

---

<div class="post-metadata">

### Author: ![DavidEGrayson](https://forum.pololu.com/user_avatar/forum.pololu.com/davidegrayson/32/4639_2.png) [@DavidEGrayson](https://forum.pololu.com/u/DavidEGrayson)
#### Post date: [December 5, 2024, 10:06pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/6 "2024-12-05T22:06:40Z")

</div>

Hello.

TicDotNet does not have a method named `set_sda_pin_mode`, and you haven’t shown us the code you wrote to call that function, so it is still unclear what code you were trying to run.

You should be able to change the function of the SDA pin via USB using the Tic’s “Set setting” command and its “Reinitialize” command. However, please see this warning about “Set setting” from the “Command reference” section of the Tic user’s guide:

> Be careful not to call this command in a fast loop to avoid wearing out the Tic’s EEPROM, which is rated for only 100,000 write cycles.

–David

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 5, 2024, 11:55pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/7 "2024-12-05T23:55:32Z")

</div>

Thank-you for the tip about the Reinitialise command.

The library I have says “Copyright 2019 Jose Ignacio Garcia de Cortazar” It has the following function

public bool set\_sda\_pin\_mode(byte sda\_pin\_mode)  
{  
return transfer(request: TIC\_SETTING\_SDA\_CONFIG, value: sda\_pin\_mode);  
}

and the following constant

const int TIC\_SETTING\_SDA\_CONFIG = 60;

It is called TicDotNet.cs. I did not write any of it and it would seem to have been written by the same person as the current one on github. Where I got the version I use I’m not sure as it was a while ago now. It does seem more complete than the current one on GitHub though.

Regards  
Tim  
[TicDotNet.cs](https://forum.pololu.com/uploads/short-url/yJmjdgDEkWuWHUsVeYW61Mw5gQd.cs) (35.0 KB)

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 12, 2024, 2:27pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/8 "2024-12-12T14:27:35Z")

</div>

Trying to set the pin modes in C# is driving me nuts. But then I’m an airline pilot not a software engineer !

Looking at the documentation I decided I’d be better of using the RX or TX pins as limit forward or limit reverse switches when needed for homing. Outside of the homing requirement I don’t want them to stop the motion so need to set them back to default.  
I’m using Visual Studio 2022 to generate and ASCOM drive for a telescope dome, at least that’s the final aim. To test things out I’m using the code from [GitHub - jigarciacortazar/TicDotNet: .NET access to Pololu TIC stepper controllers Written in C #](https://github.com/jigarciacortazar/TicDotNet) (linked to from the Pololu website) which compiles and runs ok.

I then use the Pololu Tic Control Center to test the pin modes. Initially I use the control center to set all pin modes to default. Then I disconnect. I’ve modified the TicDotNet code to have an additional button on the form. When clicked it performs the following code

```auto
private void button1_Click(object sender, EventArgs e)
{   
    m_tic.set_setting_byte(0X3D, 9);
    m_tic.reinitialize();            
}

```

I then disconnect from the TIC and reconnect to the Pololu TIC control center expecting to see that the TX Pin Mode has changed to Limit Switch Reverse, but it stays at default. I try the command of  
`Device: Reload setting from device`  
to no effect.

Please could you write the code that should be in the above Button Click function that allows me to change the TX button mode. Code that allows me to read the mode into a variable would also be helpful

Thanks  
Tim

---

<div class="post-metadata">

### Author: ![DavidEGrayson](https://forum.pololu.com/user_avatar/forum.pololu.com/davidegrayson/32/4639_2.png) [@DavidEGrayson](https://forum.pololu.com/u/DavidEGrayson)
#### Post date: [December 12, 2024, 9:00pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/9 "2024-12-12T21:00:36Z")

</div>

Thank you for providing the code you are running. The `set_setting_byte` function in `TicDotNet.cs` is incorrectly setting the `wValue` and `wIndex` fields of the USB control transfer. You should be able to fix the function by changing it to:

```cs
  public bool set_setting_byte(int address, int byte_value) {
    return transfer(request: TIC_CMD_SET_SETTING, value: byte_value, index: address);
  }

```

For more information, see the “USB command encoding” section of the Tic User’s Guide, which documents how to send a “Set setting” command.

–David

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 12, 2024, 9:02pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/10 "2024-12-12T21:02:12Z")

</div>

Thank you David. I’ll give that a go tomorrow and let you know how I get on

Tim

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 13, 2024, 3:01pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/11 "2024-12-13T15:01:15Z")

</div>

I can confirm that this works well.  
However it has highlighted another minor issue I can live with but would best be resolved. The Homing Reverse to the switch attached to the TX pin (set to Limit switch reverse) works perfectly. However setting the TX pin to Limit switch forward and then using Homing Forward does not cause the homing to stop as it passes the switch. When I’m slewing past the switch I set the TX pin to Default so that it doesn’t act as a kill switch and stop the dome rotating as used to happen  
Here’s the function to find home which sets the TX pin according to whether the shortest way to home, which is due north (000 degress) is forwards of backwards. It sets a variable Limit\_Switch\_Set to true so that the Slew routine only changes the TX pin function if it is not set to default. This was to prevent too many writes to EEPROM.

```auto
 public void FindHome()
 { //tl.LogMessage("FindHome", "Not implemented");
     //throw new MethodNotImplementedException("FindHome");                
     m_tic.exit_safe_start();
     m_tic.energize();
     Limit_Switch_Set = true;
     if (Azimuth >= 180)
     {

         m_tic.set_setting_byte(0X3D, 8);
         m_tic.reinitialize();
         m_tic.go_home(tic.GO_HOME.FORWARD);
     }
     else
     {
         m_tic.set_setting_byte(0X3D, 9);
         m_tic.reinitialize();
         m_tic.go_home(tic.GO_HOME.REVERSE);
     }

```

The slew function just checks that the Limit\_Switch\_Set is false, if not it sets the TX pin to default, and then performs the dome slew

```auto
 public void SlewToAzimuth(double Azimuth)
 {
     //make the Azimuth a golbal variable for use in the Slewing property
     TargetAzimuth = Azimuth;
     if (Limit_Switch_Set)
     {
         m_tic.set_setting_byte(0X3D, 0);
         m_tic.reinitialize();
         Limit_Switch_Set = false;
     }

     double RequiredMoveDegrees;

     double AzimuthDiff = TargetAzimuth - CurrentAzimuth;

     if (AzimuthDiff > 180)
     {
         RequiredMoveDegrees = AzimuthDiff - 360;
     }
     else if (AzimuthDiff < -180)
     {
         RequiredMoveDegrees = (AzimuthDiff + 360);
     }
     else
     {
         RequiredMoveDegrees = AzimuthDiff;
     }

     //convert the degrees to move to motor steps to move
     int TargetSteps;
     double StepsToMove = RequiredMoveDegrees * steps_per_degree;
     TargetSteps = currentMotorSteps + (int)StepsToMove;

     // have to interface with motor here to set slew in motion. After this the timer function handles de-enegising the motor once slew complete.
     m_tic.exit_safe_start();
     m_tic.energize();
     m_tic.set_target_position(TargetSteps);

 }

```

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 16, 2024, 9:30am UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/12 "2024-12-16T09:30:43Z")

</div>

One thing I’d add for anyone doing this is to screen the wires from the switch (I use a magnetic sensor as a switch) and the board. I started getting a lot of serial port errors when the motor was running and found that just by moving the wires that improved. My solution was actually just to wrap the wire from the TX pin around the wire from the gnd pin producing a twisted pair. This totally solved the interference issue. I guess using shielded wire with the shield connected to the gnd pin would be even better but the twisted pair works.

---

<div class="post-metadata">

### Author: ![DavidEGrayson](https://forum.pololu.com/user_avatar/forum.pololu.com/davidegrayson/32/4639_2.png) [@DavidEGrayson](https://forum.pololu.com/u/DavidEGrayson)
#### Post date: [December 17, 2024, 8:25pm UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/13 "2024-12-17T20:25:02Z")

</div>

I don’t see anything wrong with the code you posted, but I wonder if somehow `SlewToAzimuth` might be running in the middle of your homing routine and disabling the limit switch.

To rule out problems with your code, I recommend shutting off the C# program and then trying to reproduce the problem just using the Tic Control Center. You should be able to set the TX pin’s function to “Limit forward”, click “Apply settings”, and then run the “Go home forward” command in the Device menu.

–David

---

<div class="post-metadata">

### Author: ![TimScott](https://forum.pololu.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@TimScott](https://forum.pololu.com/u/TimScott)
#### Post date: [December 18, 2024, 10:11am UTC](https://forum.pololu.com/t/changing-sda-pin-mode-in-software/27213/14 "2024-12-18T10:11:53Z")

</div>

Thanks David

The SlewToAzimuth routine will only run if the dome is commanded to track the telescope, or I command the dome to rotate to a specific azimuth via the ASCOM interface. When the dome is commanded to Home then the tracking element is automatically switched off by the ASCOM software. But I will try your suggestion of using the Tic Control Center to test it out

Tim
