0
\$\begingroup\$

I had a pretty straightforward question: Is it possible to control the current in a circuit using Python? If yes, what device do we need to do so? I only possess knowledge on Physics and not on Electrical Engineering, so I would really appreciate if the technical terms used in your answers are simple to understand and if you do use some, then please explain the meaning of that term. Hours of browsing on the internet returned nothing. I did find one article though, but it was probably not what I was looking for so I won't be linking that here. If we cannot control the current using python, then can we do so using some other programming language?

If the above isn't possible, then how do I set up a current source whose current I can vary at will but not mechanically(i.e., by pressing a button or rotating a dial) and instead using a computer.

Thanks in advance!

EDIT: In response to @Transistor's queries:

  1. Computer Systems available: Windows,Linux and Rpi. But Rpi is the least preferred
  2. Current range: 0-2A
  3. Hobby, lab or industrial?: Lab
  4. Level of precision: I want to try controlling this first, and later think about precision. So I hope that I have clarified any context that you guys wanted. Now after reading the comments and the answer, I would remind you to kindly elaborate a little more in layman terms as I am not familiar with a lot of Electrical Engineering. Even some reference links will suffice.

EDIT 2 Okay so after a lot of browsing, I have gained more knowledge. Jonk says that I can buy a programmable current source. However the issue is that there is no programmable current source that I found. If you know of such a current source, then please tell me the model number/provide a link. Now coming to what I have found. I have found some programmable power sources. Although a programmable power source is something I do not prefer, if there's no programmable current source out there, then here's the idea that I have: If we operate the Programmable Power Source in CC(Constant Current) mode and then using a Python script and SCPI, I use a for loop in which the current value increases or decreases in every iteration, then I'd be done! My question is therefore:

  1. Is there a programmable current source in the market? A preferred budget would be 25,000 INR. If yes, please tell which one.
  2. If answer to question is No, then will the current actually vary in the circuit if I try to implement the idea that I have described about the programmable power supply?
\$\endgroup\$
12
  • 3
    \$\begingroup\$ This is a hardware dependent. (1) What is the computer system? (2) What is the current requirement? (3) What is the maximum voltage required? (4) Hobby, lab or industrial? (5) What level of precision? (6) What's the budget? \$\endgroup\$ Commented Sep 19, 2021 at 19:44
  • 2
    \$\begingroup\$ A bench power supply with USB/serial connection and libraries available. Or cards from National Instruments with analog output to control your own bench. \$\endgroup\$ Commented Sep 19, 2021 at 19:58
  • 1
    \$\begingroup\$ For a pretty straightforward question you do need context. The comments are asking for context! Without that your pretty straightforward question is unclear and will probably be closed. \$\endgroup\$ Commented Sep 19, 2021 at 20:42
  • 1
    \$\begingroup\$ The short answer is Yes. The long answer requires at least some specification of what you need. What current range? what voltage range? A high side drive or low side drive, or floating, or optically isolated from your computer? Some hints might help other offer advice. \$\endgroup\$ Commented Sep 20, 2021 at 0:30
  • \$\begingroup\$ @Tesla You will want some way to program digital values into a DAC, which will produce an analog voltage for you based on the digital value that you program into the DAC. That voltage can then be used to control a circuit (which you need) that can convert the voltage into a current source/sink result into a load. You will need to specify many things. But yes, it can be done using Python if and only if you have such a system that Python can communicate with. This can be over USB. But that's only one possibility of many. You need to specify that, as well. \$\endgroup\$ Commented Sep 20, 2021 at 3:16

2 Answers 2

1
\$\begingroup\$

The main thing you need is a current source that can plug into a computer.

From scratch an MCU controlled current source with a USB-UART bridge. The bridge is a USB adapter that, with the right PC drivers, appears as an RS-232 port (virtual COM port) on the PC. The other end plugs straight into the microcontroller's UART.

That way you can use USB ports in hardware but treat it as the older RS-232/UART/hyperterminal in software. Much easier than using native USB.

Then use python to send terminal commands through the virtual COM port.

\$\endgroup\$
10
  • \$\begingroup\$ I would have thought that a filtered PWM driving a 0 - 5 V controlled current source would be the way to go. \$\endgroup\$ Commented Sep 19, 2021 at 19:47
  • \$\begingroup\$ @Transistor PWM? From a USB-UART bridge? \$\endgroup\$ Commented Sep 19, 2021 at 19:49
  • \$\begingroup\$ No, but you brought in those constraints, not the OP. I would have gone for some sort of analog I/O solution rather than introduce another MCU. Let's see what the OP comes back with after my OP comment. \$\endgroup\$ Commented Sep 19, 2021 at 19:53
  • \$\begingroup\$ @Transistor Did you miss the part about a computer+Python? I interpreted that as a PC. Unless you know a way to get an analog or PWM straight out of a PC. \$\endgroup\$ Commented Sep 19, 2021 at 19:54
  • 1
    \$\begingroup\$ I saw that OK but thought it could be an RPi or something else. Here's a USB to PWM module found on a quick web search. \$\endgroup\$ Commented Sep 19, 2021 at 20:04
0
\$\begingroup\$

Although RPi is your less preferred computer, it would probably be substantially easier than a typical laptop, since it has a PWM (Pulse Width Modulation) module on it. Like Transistor suggested early on, filtered PWM to a voltage-controlled current source (basic disussion here) seems quite straightforward. See diagram below. You use the RPi to output PWM (which you can do in Python), then run a low-pass filter on that output. The resulting filtered voltage is then the input to your voltage-controlled current source.

enter image description here

If you want to avoid the RPi, then you introduce a step up in complication because you need something to interface with the USB computer output. One example is this module, which will enable you to use various types of serial communication through your computer's USB port. You can drive it with some Python libraries. One reasonable choice for serial protocol would be I2C, which is a serial communication protocol used by many integrated circuits (many online references, here is one). You could, for instance, interface this to a Digital-to-Analog Converter (DAC) that uses I2C, such as this one, which would give you the voltage you need to connect to your voltage-controlled current source.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.