logo elektroda
logo elektroda
X
logo elektroda

Arduino & Python Programming: Building a Locomotive Tester with 27-Pin Communication Cable

carefree 9729 22
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18135133
    carefree
    Level 17  
    I was programming as a kid in basic, then had Pascal in school. However, I never got to any particular level. The basics are there, the logic is. I want to learn to program Arduino. For example, I want to build a tester for locomotives and carriages (I work at the American PKP, or more precisely, WKD). The cable for communication between the controlling car and the locomotive has 27 pins, almost each of them has its own function. The devices we use are built years ago by workers and clunky (boxes on wheels). The new device could, for example, have an LCD touch display and work remotely.
    Now for the concrete.
    I have been looking for a good answer to my question for some time. Everywhere, on the electrode too, someone will explain something, but it does not satisfy me.
    I know Arduino is best programmed in C / C ++ and I understand why, but I still want to learn Python. It is simple, popular, universal. I will write a script for arduino or Windows / Android applications. There are Python Arduino Courses.
    Is it worth learning to program Arduino in python? What are the limitations / differences compared to C / C ++.
    Why should I not program Arduino in Python?
    Will someone explain to a man who has something in his head but has never seriously programmed?
    I am an electronics technician by profession.
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 18135151
    dasej
    Level 32  
    Hello.

    Another software frontend to something that should be programmed in asm.
    The first basic question is how many bugs it has.

    Every compiler makes mistakes. As in your opinion, Python has more or C which is used by almost the entire world writing software.
    An algorithm written in C can also be easily transferred from CPU to CPU. Producers provide environments that are up to date with the novelties produced by them.
    How other environments are to keep up with it.

    Each big facilitation takes you away from the possibility of using the processor as much as possible.
    C projects written with 90% flash usage, in the case of Arduino it will not fit in the same processor. The code will take about 130% of flash.

    I had a short time playing Arduino, it's just a waste of time.

    Why are they pushing Python so much? That you, as a programmer, leave behind the sources, the employer's philosopher.
  • #3 18135236
    chudybyk
    Level 31  
    Also, I think Python on Arduino is more of a curiosity than a useful tool. Python is a scripting language, it needs a specific environment to run, which can be provided by an operating system with much more resources than Arduino. I would be afraid to run something in this environment that contains more than a few dozen lines of code. For this I have doubts how many Python libraries are able to run on Arduino. There is a huge chance it will crash out immediately after booting up.
    Personally, I would advise you to program in Python under a slightly larger platform, for example Raspberry Pi, which is a full-fledged Linux and Python has a chance to run on it without major problems. The convenience of work is also incomparably greater.
    Another issue worth considering is safety. If you want to use a device and program in railways, there are certainly rules and standards regulating the safe use of electronic equipment and embedded software. Make sure that using your own inventions will not endanger your life or health and, as a result, legal liability.
  • #4 18135447
    osctest1
    Level 21  
    There is no clear answer to this question.

    1. If it is an Arduino with a sufficiently large ARM (or another with the right amount of resources - eg ESP) - then there are no obstacles. There are tons of implementations (e.g. mikropython) and you can play as much as you want.
    2. If it is UNO or MEGA then it is IMO impossible. The microcode interpreter takes some resources, and I haven't heard of any implementation working. There are solutions, however, that the python program is executed on a PC and the commands related to the Arduino hardware (ADC, PWM, GPIO ...) are sent via USB to the arduino, on which the appropriate program for interpreting these commands is running.


    dasej wrote:
    Every compiler makes mistakes.
    R2D2 also, but not often. The compiler doesn't make mistakes, nor is there any awareness that the compiler can have errors caused by programmers who make mistakes quite often.

    dasej wrote:
    Each big facilitation takes you away from the possibility of using the processor as much as possible.
    How does C or C ++ take away from it? Holy (and already lost 1e9 times) war of the Asm-Riders?

    dasej wrote:
    Why are they pushing Python so much? That you, as a programmer, leave behind the sources, the employer's philosopher.
    And when you write at ASM for some crazy employer, don't you leave your sources? There is no code review - where will you confess all your secrets and "myths" ?. So what's the difference in what language do you write? The employer will get exactly the same (or rather more in ASM because he will want very detailed comments).
  • #5 18135458
    khoam
    Level 42  
    carefree wrote:
    Why shouldn't I program Arduino in Python?

    There is no such thing (real) as programming in Python with the Arduino HAL. There is a "lightweight" Python implementation for 8-bit processors ( PyMite ), but it has nothing to do with Arduino and is generally unusable.

    It is available for hardware platforms based on ESP8266, ESP32 or some STM32 MicroPython , in the form of a dedicated firmware containing an interpreter - here again, it has nothing to do with the Arduino HAL.

    Boards (modules) known colloquially as "arduin" do not necessarily have to be programmed with the Arduino HAL and vice versa: wanting to use Arduino HAL you do not need to use ready-made modules called and sold as "arduin".
  • ADVERTISEMENT
  • #6 18135680
    kaczakat
    Level 34  
    It depends on what this LCD screen is for, e.g. I recently read the message: "The US Navy will abandon the touch screens for throttle and rudder control, which are currently installed on destroyers. It is a reaction to the report on the collision of the ship with the tanker in 2017. "The Verge said." So it turns out that where precision and reliability are required, LCD screens turned out to be a dead end.
    Arduino with C ++, lots of courses, tutorials, examples and ready on the Internet will probably be easier than python. While learning Arduino, I haven't created any question post yet, usually google related is enough, so far all issues have been resolved before I encountered them. Even looking at this forum, there is an Arduino section, ESP (and rather as a sticker for Arduino and C / C ++), AVR, ARM and PIC with C (BASCOM remnants), no python section for uC. If you want to be a pioneer, that's OK.
    Helpful post? Buy me a coffee.
  • #7 18136181
    osctest1
    Level 21  
    carefree wrote:
    . For example, I want to build a tester for locomotives and carriages (I work at the American PKP, or more precisely, WKD).
    I just read this sentence. I am afraid that
    carefree wrote:
    Will someone explain to a man who has something in his head but has never seriously programmed?
    that it is unfortunately impossible. I doubt that any apparatus used in work with locomotives is uncertified and not subject to appropriate standardization.

    In addition, for some reason, companies producing service / measurement equipment for the transport industry employ a large number of highly paid programmers.

    Forget arduino and programming from Internet courses when designing devices for use in such a professional application
  • #8 18136331
    Simon79
    Level 21  
    If my colleague is interested in connecting Python with electronics, maybe Raspberry pi?
  • #9 18136625
    ppc
    Level 18  
    carefree wrote:
    (I work at the American PKP, or more precisely WKD)


    Where are you from?

    If I were you, I would focus more on the interface between the car and the computer (car to USB or something wireless) - you will then be able to base the software on the computer / tablet / mobile instead of the Arduino (not developmental in my opinion).

    Having a computer interface, you can have both a touch screen and the ability to automatically create a test report (Americans like it) or report further to a database / headquarters.
  • #10 18136812
    osctest1
    Level 21  
    @ppc These 27 pin connectors are the so called MU (Multi Unit) used by US railways. The voltages are 0-74V + something else that I don't remember. All control and measurement devices connected to the locomotives and carriages must be certified.

    Even if you have some old, uncertified ones made - it is precisely because what was used when the certification rules came in - could be used on (because the railway would be left without devices).

    Nobody will connect any self-made device to something that is improperly checked and can cause damage that is difficult to imagine. Imagine a situation that such a device gave a signal incorrectly, e.g. when checking the tightness of the pneumatic system, and the train was derailed. A company that would allow such negligence would pay exorbitant damages and penalties (not counting criminal proceedings for supervisory staff).

    Therefore, writing about learning to write in Python by watching a tutorial to make a railroad diagnostic device is mildly frivolous.
  • #11 18137286
    gielo2
    Level 11  
    chudybyk wrote:
    Also, I think Python on Arduino is more of a curiosity than a useful tool. Python is a scripting language, it needs a specific environment to run, which can be provided by an operating system with much more resources than Arduino. I would be afraid to run something in this environment that contains more than a few dozen lines of code. For this I have doubts how many Python libraries are able to run on Arduino. There is a huge chance it will crash out immediately after booting up.
    Personally, I would advise you to program in Python under a slightly larger platform, for example Raspberry Pi, which is a full-fledged Linux and Python has a chance to run on it without major problems. The convenience of work is also incomparably greater.
    Another issue worth considering is safety. If you want to use a device and program in railways, there are certainly rules and standards regulating the safe use of electronic equipment and embedded software. Make sure that using your own inventions does not cause any threats to life or health, and as a result, legal liability.


    Yes, Phyton was developed as a scripting language, but you don't program a microcontroller in the scripting language, so you need a compiler for that. The compiler, on the other hand, makes such a scripting language, in a given case, a language compiled into machine code. (Personally, I don't like Python, maybe because I'm a mathematician by training and C / C ++ is more logical for me). In this case, the quality of such a compiler (what code it generates) and the programmer's skills are more important than the programming language itself.

    As for arduino, you probably don't quite understand what it is. Arduino is a library (programming, not hardware), not an operating system, or some exotic programming language as some people think:] Syntactically it is largely compatible with C ++, you can also use syntax and commands in C. It is thanks to this library and the compiler produces binary code that you can run on the microcontroller. The result code, on the other hand, is closely related to the quality of the compiler, not the programming language itself, and the library itself. By the way, by programming in arduino, you can run the program on the microcontroller itself, also without a bootloader. As for the assembler itself, it is just rubbish as if it is a way to deal with all problems with code performance and quality. It may or may not be, because it depends on a really broad knowledge and skills of such an assembler programmer. The authors of compilers most often have such knowledge and skills, also about any tricks with the code, hence often the compiler's output code will be of much better quality than the assembler from an average programmer's finger. Advanced compilers like GCC and clang are quite intelligent these days and optimize the object code to be as optimal as possible (concise and efficient). It is true that the assembler itself also requires a compiler, but here the matter is more compiled, so that the result code can be optimized efficiently.

    As for security. You haven't elaborated on what exactly are you talking about. You can protect the code against theft by blocking the possibility of copying it from the microcontroller, as for security in terms of its inappropriate use, it is the programmer's gesture, not the language itself. If the program is to control some wifi or bluetooth equipment, or you want to avoid the so-called memory leaks etc. you should simply know what you are doing, especially in the case of commercial use of a program you wrote, including any additional libraries you want to use. I program in C ++ myself, which scare children about how hard to grasp and dangerous language due to memory leaks, repeating myths from the 1980s. Currently, however, both C ++ and other modern languages have mechanisms to prevent such a memory leak. Some have something like Garbage Collector, such as C #, or intelligent pointers such as C ++ 11 and higher. So let's know the exact language you are using and use the newest versions possible:]

    As for the scripting languages such as Python, virtual machines like java, bit codes in C #, etc. Many of them also allow you to compile the code directly into the machine code, directly, or convert it first to C / C ++ as it does, for example, Qt and then its compilation. This is to illustrate how the language can be used for purposes that we would not have been able to do in the original.
  • #12 18137544
    khoam
    Level 42  
    gielo2 wrote:
    It is largely compatible with C ++ syntactically, and you can also use syntax and commands in C.

    Syntactically, it is 100% C ++ compatible, because Arduino HAL is written in C ++, except for a small part that uses assembly language (depending on the hardware platform). It has also been known for a long time that when programming in C ++ you can use the syntax and commands from the C language.

    gielo2 wrote:
    By the way, by programming in arduino, you can run the program on the microcontroller itself, also without a bootloader.

    The optiboot bootloader is not used to launch programs, but to load them via the UART interface.

    gielo2 wrote:
    C ++ and other modern languages have mechanisms to prevent such memory leakage. Some have something like Garbage Collector, such as C #, or intelligent pointers such as C ++ 11 and higher.

    C ++ does not have built-in garbage collectors, such as C # or Java, and the so-called "smart" pointers are as intelligent and as safe from memory leaks as the programmer who uses them correctly is.

    gielo2 wrote:
    or I will first convert to C / C ++ as it does eg Qt and then compile it

    The Qt library is written in C ++. It uses specific macros to handle signals and slots that are part of the C ++ macro processor.
  • ADVERTISEMENT
  • #13 18137573
    osctest1
    Level 21  
    khoam wrote:
    but for charging them via the USB interface.
    definitely though via UART. Optiboot knows nothing about USB.
  • #14 18137578
    khoam
    Level 42  
    osctest1 wrote:
    definitely though via UART. Optiboot knows nothing about USB.

    That's true. I used an unfortunate mental shortcut. Thank you for rectifying.
  • #15 18137649
    gielo2
    Level 11  
    khoam wrote:
    gielo2 wrote:
    It is largely compatible with C ++ syntactically, and you can also use syntax and commands in C.

    Syntactically, it is 100% C ++ compatible, as Arduino HAL is written in C ++, except for a small part that uses assembly language (depending on the hardware platform). It has also been known for a long time that when programming in C ++ you can use the syntax and commands from the C language.

    gielo2 wrote:
    By the way, by programming in arduino, you can run the program on the microcontroller itself, also without a bootloader.

    The optiboot bootloader is not used to launch programs, but to load them via the UART interface.

    gielo2 wrote:
    C ++ and other modern languages have mechanisms to prevent such memory leakage. Some have something like Garbage Collector, such as C #, or intelligent pointers such as C ++ 11 and higher.

    C ++ does not have built-in garbage collectors, such as C # or Java, and the so-called "smart" pointers are as intelligent and as secure against memory leaks as the programmer who uses them correctly is.

    gielo2 wrote:
    or I will first convert to C / C ++ as it does eg Qt and then compile it

    The Qt library is written in C ++. It uses specific macros to handle signals and slots that are part of the C ++ macro processor.


    1. It is not 100% compatible and that it is written in C ++ does not prove anything. Many other languages are also written in C ++, eg the first versions of C # were written in it, which does not mean that they were compatible with c ++:] You see c ++ is not only a compiler but also a standard library. which was not completely attached to the arduino.

    2. Exactly, that's why I wrote that you can run such a code without the arduino bootloader. I did not write why, because I think that having access to the electrode, he also has access to the Internet and everyone can read it to learn something new. Unless he knew it before, of course.

    3. does not have GC, which I wrote about, for example, C #, and C ++ has intelligent pointers. You are right about smart pointers, but using smart pointers is much simpler than malloc and free in C, or even new and delete in C ++. That you can kick if you don't know how to use? Sure you can. However, you can kick many things if you don't know how to use them. Smart pointers are designed to make life easier for programmers so that they can avoid leakage errors, rather than relieve them of their thinking.

    4. No matter what Qt is written in, it was written not only in C ++ itself but also in JS for example, it doesn't matter. The topic concerned how to compile a language code into machine code, which was not intended to be compiled to such code. In Qt, you can use C ++ to write programs (not only window-based) and this is standard, but you can also use Java and Python. The last two, however, are first translated into C ++ code and then compiled, which does not mean that they do not existto them individual compilers, directly compiling the code of these languages (using other libraries) into machine code. There is also a creation like QML based on JS. Qt itself is not only a library but the whole freamwork, code editor, graphic editor etc. etc. In the last version of Qt, also website elements using webassembly can be written in it. However, that was not what the topic was about.

    To sum up, the programming language is not important as much as it seems to some people, but the object code run on such a microcontroller (I omit the elements of source code readability, the ease and speed of writing the program). However, this one depends mainly on the compiler as well as the skill of the developer himself. If the author persists in programming in Python and learns or knows the language well and will find a good AVR compiler for him, why not?
  • #16 18137674
    khoam
    Level 42  
    gielo2 wrote:
    1. It is not 100% compatible and that it is written in C ++ does not prove anything. Many other languages are also written in C ++, eg the first versions of C # were written in it, which does not mean that they were compatible with c ++:] You see c ++ is not only a compiler but also a standard library. which was not completely attached to the arduino.

    It is written in C ++. I suggest you take a look at (implementation for AVR and ESP32):
    https://github.com/arduino/ArduinoCore-avr/tree/master/cores/arduino
    https://github.com/espressif/arduino-esp32/tree/master/cores/esp32
    This C ++ compiler for AVR does not come with the std library, so it is not the Arduino HAL's fault for this hardware platform.
    You see, Arduino is not only AVR, when you use e.g. Arduino HAL for ESP32, you have full C ++ 11 at your disposal.

    gielo2 wrote:
    4. No matter what Qt is written in, it was written not only in C ++ itself but also in JS for example, it doesn't matter. The topic concerned the method of compiling a language code into machine code, which was not intended to be compiled to such code. In Qt, you can use C ++ to write programs (not only window-based) and this is standard, but you can also use Java and Python.

    The Qt library was written in C ++. There are so-called wrappers for this library in different languages that are a secondary product of this library. You provided imprecise information about this library, so it had to be corrected.
  • ADVERTISEMENT
  • #17 18137740
    gielo2
    Level 11  
    khoam wrote:
    gielo2 wrote:
    1. It is not 100% compatible and that it is written in C ++ does not prove anything. Many other languages are also written in C ++, eg the first versions of C # were written in it, which does not mean that they were compatible with c ++:] You see c ++ is not only a compiler but also a standard library. which was not completely attached to the arduino.

    It is written in C ++. I suggest you take a look at (implementation for AVR and ESP32):
    https://github.com/arduino/ArduinoCore-avr/tree/master/cores/arduino
    https://github.com/espressif/arduino-esp32/tree/master/cores/esp32
    This C ++ compiler for AVR does not come with the std library, so it is not the Arduino HAL's fault for this hardware platform.
    You see, Arduino is not only AVR, when you use e.g. Arduino HAL for ESP32, you have full C ++ 11 at your disposal.

    gielo2 wrote:
    4. No matter what Qt is written in, it was written not only in C ++ itself but also in JS for example, it doesn't matter. The topic concerned the method of compiling a language code into machine code, which was not intended to be compiled to such code. In Qt, you can use C ++ to write programs (not only window-based) and this is standard, but you can also use Java and Python.

    The Qt library was written in C ++. There are so-called wrappers for this library in different languages that are a secondary product of this library. You provided imprecise information about this library, so it had to be corrected.


    The topic was not about Qt itself, which I wrote about, but it was just an example of how Qt allows the use of languages other than C ++ (not compiled into machine code, as standalone software) with regard to memory management. It is not a thread of discussion in itself. So I do not think that further discussion about it is appropriate here and makes any sense. If you are interested, please visit https://www.qt.io/, i.e. to the sources.
  • #18 18137773
    uzi18
    Level 24  
    It depends on which arduino board it is because, for example, on ESP8266 there is a python port - micropython
  • #19 18140582
    carefree
    Level 17  
    The device that I am talking about would be very simple. In fact, the screen would show only the status of the pins from the wagon or locomotive, e.g. forward, reverse, notch (positioner position), etc. The only thing I would like to remotely start from the device are 3 pins: wheel skid alarm, open ramp for wheelchairs and a signal closed doors on the train. These are the control lamps in the cabin that we test during the locomotive functional test. Today we put a plug with three buttons on a long cable in the sockets outside. Never in my life would I try to control a locomotive with any unauthorized device. Rather certain that sooner or later it would end badly.
    The pin status would be displayed on the LCD to check for problems between the relays in the control cabinet or the switches and the socket.
    And a remote device, because why go down and enter the locomotive with a multimeter every time I do something, when I can see it on the LCD while I work in the cabin.
    I don't think I will need anything more advanced than arduino plus a few modules for this. Device cheap, only design and write a program.
  • #20 18140639
    Anonymous
    Level 1  
  • #21 18140838
    uzi18
    Level 24  
    A total of 2x esp8266 is enough, one in AP mode, the second connected to it, one shows the interface, for example on a smartphone / LCD, and the other gives control signals, it will be definitely cheap.
  • #22 18140860
    Anonymous
    Level 1  
  • #23 18141613
    uzi18
    Level 24  
    o_Tadeusz wrote:
    uzi18 wrote:
    a total of 2x esp8266 is enough

    One ESP and a smartphone will do the trick.

    All in all right

Topic summary

The discussion revolves around programming Arduino for building a locomotive tester that utilizes a 27-pin communication cable. The user expresses a desire to learn Arduino programming, particularly in Python, despite the community's consensus that C/C++ is more suitable for Arduino due to its resource constraints. Various responses highlight the limitations of using Python on traditional Arduino boards like UNO or MEGA, suggesting alternatives such as Raspberry Pi or ESP8266/ESP32 for Python applications. Concerns about safety, certification, and the reliability of using homemade devices in railway applications are emphasized. The conversation also touches on the potential for using a simple interface with an LCD display to monitor pin statuses and control signals remotely, with suggestions for using ESP modules for a cost-effective solution.
Summary generated by the language model.
ADVERTISEMENT