Category: Uncategorized

  • DF1201S MP3 PlayerPro & Arduino

    One of my uses for this blog to is to record useful information that I (and others) might need later. This is about an annoying problem I ran into.

    I’ve used the DfRobot Player Pro a couple of times in “stand alone” mode. It’s a great audio player: small, cheap, and easy to use. It also has a serial interface so it can be controlled by an arduino or microcontroller. DF Robot provides the DFRobot_DS1201S library to make this easier. However, all the examples I see online are using the playFileNum(num) command that takes an index of a file (MP3) to be played. The problem with this is that the file index depends on the order in which the file file was stored to the Player Pro’s Flash memory.

    There is also a playSpecFile(String) method that takes a filename, which you’d expect is much easier and would be more popular. However, when I tried using it, it always played the same song. OK, time to debug. There is also a method in their library to retrieve the name of the currently playing file. However, when I use code like this:

    // Play file
    DF1201S.playSpecFile("one.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    DF1201S.playSpecFile("two.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    DF1201S.playSpecFile("three.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    

    It always plays the same song and to boot, I get Chinese characters displayed for the file name. Clearly, not what I was trying to play.

    However, make a minor change to the filename and this works.
    

    // Play file
    DF1201S.playSpecFile("/one.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    DF1201S.playSpecFile("/two.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    DF1201S.playSpecFile("/three.mp3");
    // Print name of file that's playing
    Serial.println(DF1201S.getFileName());
    

    This plays three different songs correctly and their filenames are reported accurately.

    HTH everyone who’s run into the same problem 🙂




    If you’d like to subscribe to this blog, please click here.

  • Replace encoder with resolver

    Yes, you read that right. You can go digital-to-resolver in addition to the more common resolver-to-digital. The converter also takes 0-10V signals and can output a corresponding resolver sine-cosine phased signal.




    If you’d like to subscribe to this blog, please click here.

  • Arduino Digimatic

    I have one of these Mitutoyo Digimatic indicators and thought it would be fun to get a larger display and to be able to record data.

    For those who aren’t familiar, Mitutoyo is an instrumentation company that builds amazing measuring instruments. The image above is a digital dial indicator that measures to a precision of 0.0001″ and can be switched between inch or millimeter units. It uses a vacuum fluorescent display, so it’s readily visible, but kind of a power hog.

    Digimatic is a product line dating back to at least the 80’s that provides measurement data digitally from the device. It’s a pretty simple protocol and easily decodable with Arduino.




    If you’d like to subscribe to this blog, please click here.

  • Sensor data into your PC

    Software and hardware integration is a general term for accessing external hardware devices from your PC, tablet or phone. Most existing systems handle common devices such as a printer, as part of the normal operations. But what about a weigh scale? Or a temperature sensor? Or a counter? What if you need to track when an item enters a manufacturing cell and again when it leaves? There are examples of sensor data that your desktop PC or server is not equipped to handle without additional software drivers or specialty applications.

    Communication channels

    Ethernet, USB, Wi-Fi and Bluetooth are all modern methods of communicating with external devices. There are older communication channels such as RS232 serial that is not well supported by modern PCs. Newer scales often use USB or Ethernet these days.

    Wi-Fi and Bluetooth have become very popular for sensor communications because they remove the need for a physical cable connecting the sensor and computer.

    While RS232 is a very old protocol (it dates back to the late 1960’s!) that is not directly supported by hardware in modern PCs, it has been so popular over the years that alternate ways of connecting to RS232 ports have arisen. Typically, if you have a PC and need to connect to something with an RS232 serial port, such as a scale, you can use a USB to Serial adapter to handle this task.

    Hardware/software integration, also known as system integration, involves combining hardware components and software applications into a cohesive system. This process ensures that different hardware and software elements work together seamlessly, allowing for efficient data sharing and process automation.

    Key Components of Hardware/Software Integration:

    1. Hardware: Physical devices such as sensors, cameras, or measuring instruments.
    2. Sensors: Convert analog signals from hardware into digital data.
    3. Connectors: Communication buses like USB, Wi-Fi, Bluetooth, or Ethernet that transfer data between hardware and computers.
    4. Software: Programs that control hardware tasks and process data.

    Benefits of Integration:

    • Improved Efficiency: Streamlines workflows by enabling different systems to communicate and share data.
    • Cost Savings: Often cheaper than replacing disjointed systems with a new one.
    • Enhanced Decision-Making: Provides accurate and comprehensive data for better analytics and reporting.

    Challenges:

    • Compatibility Issues: Different systems may use various technologies, requiring significant effort to integrate.
    • Security and Compliance: Ensuring data security and compliance with regulations can be complex.

    Examples:

    • Temperature Monitoring: Systems that record and report temperature data from thermometers.
    • Food Wastage Monitoring: Applications that track food wastage using weighing scales and cameras.




    If you’d like to subscribe to this blog, please click here.

  • Encoder to Resolver

    Description

    Converts 0-10V absolute position or quadrature encoder position outputs to resolver (sin/cos) format for motion control retrofit.

    Specifications

    • 12-bit resolution differential sine/cosine resolver outputs
    • Resolver output swing (bipolar): 12VAC max.
    • Resolver excitation input range: 12VAC max. @ 15 kHz
    • 0-10V position indicator input
    • Quadrature encoder (differential) digital inputs
    • Encoder input rate: 100kHz minimum
    • Power supply input: 24VDC
    Resolver signal
    Resolver signal



    If you’d like to subscribe to this blog, please click here.

  • Arduino Programming: About time

    Time is probably the most commonly controlled process variable. Timers are all over the place in industrial control. Odds are, if you need some type of timer, no matter how strange, you can find it off the shelf.

    Now, many of these timers used a chip usually referred to as the “555.” The LM555 originally made by (I think; someone will correct me) National Semiconductor was a very versatile device, but it was at the heart of many time-delay relays, short timing circuits, etc.

    So once upon a time, if you wanted to build a basic timer, odds are you would wire up a 555 into a circuit. To build a handful, or just one, you’d use a perf board,

    perfboardmaybe you might use wire wrap or even dead-bug construction (my favorite!)

    deadbug

    It would be time consuming,but maybe you had no choice because the timer had some weird requirement that no off the shelf timer had, or needed to fit into an oddly shaped space.

    What does this have to do with Arduinos? Well, you can program any timing sequence into an Arduino. Say you want the heater on a commercial ironing board to come on for five seconds when the operator lowers it, a 555 does it easily. If you want the heater to come on for five seconds and when the board is raised again, a fan to blow for 10 seconds to cool the clothing, the 555 can still be used. Maybe you need two of them. But now, the Arduino becomes an easier solution. Whether you need one time sequence, or dozens, a single Arduino can be programmed to do it. When you factor in the labor of wiring a circuit board with the 555, the low off the shelf price of the Arduino makes it even more attractive.

    This is the wonder of the time we live in: an off the shelf microprocessor board is now inexpensive enough to be used for logic replacement.

    Amazing


    If you’d like to subscribe to this blog, please click here.

  • Don’t do what Donny Don’t does

    Item #1: do not try to power motors from the Arduino 5 volt output pin. There, I said it.




    If you’d like to subscribe to this blog, please click here.

  • All about resistors

    Resistors are one of the fundamental electronic components. They fall into the category of linear devices because their behavior is predictable by a linear equation. That is, the voltage across a resistor is a linear multiple of the current passing through it:

    voltage (V) = Current (i) x Resistance (R)

    Important resistor characteristics

    The resistance, the amount that a resistor impedes or “resists” current flow, is measured in ohms. Commonly, the Greek letter omega Ω is used as an abbreviation. e.g., a 10,000 ohm resistor is shown as 10kΩ. The power rating of a resistor is measured in Watts (W). In many applications, the power rating is important because if it is exceeded, the resistor will become very hot and physically fail, possibly even bursting into flames. For most applications in Arduino-based circuits, power is not likely to be a significant issue.

    What they look like

    Resistors can take a lot of different physical shapes. Here are a few examples.

    1.5ohm, 10Watt Power resistor

    (By Emilian Robert Vicol from Com. Balanesti, Romania – Ceramic-Encapsulated-Resistor_23268-480×360, CC BY 2.0, https://commons.wikimedia.org/w/index.php?curid=38383544)

    Various through-hole resistors

    Surface-mount resistors

    Electric kettle

    Yes, an electric kettle is an example of a very high-power resistor. It uses the resistance of high-temperature wire to turn the electricity into heat.

    What do we need them for?

    The function of a resistor is to impede current flow. That’s it. That’s literally all they do. However, that simple statement means that they can be used for lots of different things.

    Pullups/pulldowns the digital inputs to a microcontroller need to have a set HIGH or LOW state. This means that they must be fixed to the positive voltage supply (Vcc) or ground (GND). Leaving them to find their own voltage level can cause the state of the input to be constantly changing between HIGH and LOW as that floating voltage changes. A pullup or pulldown resistor is normally used if the device that is driving the input does not have a natural HIGH or LOW state. We would not want to connect the input directly to Vcc or ground, because in that case, if we were to connect the input to a signal that changes the inputs’s state, it would mean a short circuit between Vcc and ground, which is a serious problem.

    One example of such a device would be a switch. Most modern processors include an internal circuit that allows the programmer to enable the input to be pulled up to Vcc, but still allows a switch or other device to drive the input to a LOW state. This is called an “internal pull up.” In many cases, an internal pull down can also be configured.

    If the processor does not have built-in pull ups, or if a stronger pull up is needed (the internal ones are quite weak: on the equivalent of a 100k resistor), then an external resistor can be used in this case.

    Current limiting This circuit uses a resistor to limit the current through a Light Emitting Diode (LED). Without the resistor, the LED would consume too much current and likely fail from overheating.

    LED current limiter

    A pair of resistors can reduce a voltage. In the diagram below, there are two resistors, R1 and R2. The zigzag is the standard schematic diagram symbol used to depict a resistor. Here an input voltage, Vin, is changed by the formula below to an output Vout. This circuit configuration is called a voltage divider because it divides the input voltage by a fixed amount.




    If you’d like to subscribe to this blog, please click here.

  • Arduino PLC setup

    Oops! Forgot to include the stacklight I mentioned in the previous post.




    If you’d like to subscribe to this blog, please click here.

  • Arduino 10MR & 10MT PLC modules

    I’ve been seeing these Arduino-based “PLCs” on the internet for a while. If you’re not familiar with PLCs, they are basically control computers with built-in or expandable Inputs and Outputs and are used for industrial control. They are typically hardened against accidental overload (too much current on the output or wrong polarity voltage on inputs) and run on 24VDC They’re built to work reliably in a harsh industrial environment. They are also usually quite expensive, although there are low-priced versions available, such as the Click PLC starting around $100 each.

    There have been industrialized versions of Arduino-based controllers for years. I have built a few projects based on the Industruino, for example, and I quite like it.

    But these new versions like the 10MT and the 10MR address the lower end of the market that doesn’t require that level of “toughness”. I was curious, so I picked up a couple. They’re cheap, right, so how can you go wrong?

    10MR PLC

    First impressions are that it looks pretty good. It’s mountable either by DIN rail or four screw holes in the feet. The material seems to be ABS plastic. Polycarbonate would have been nice. Programming is via a DE-9 serial port, so you will need to connect it to a serial port. A USB-to-serial converter should work just fine. The connections are by rising-cage screw terminals, which was a nice surprise. Most Arduino clone connectors use the super cheap and annoying terminals that can’t grip wire properly unless you use ferrules. I mean, these are cheap terminals, but not the bottom of the barrel. These actually work fairly well.

    The module comes with four optically-isolated FET open-drain (aka “NPN”) power-driver outputs or relays, depending on the version you choose. Outputs are labelled Y0 through Y3 and are assigned to Arduino pins 9 – 12. The 10MR has relays and the 10MT has transistors. There are also 6 digital inputs and 3 analog inputs and a 2-line, 16 character LCD. The units specify a 24VDC power supply, but I have successfully run them from 12V also.

    Overview

    So far I’ve only used the outputs on the 10MR and aside from a momentary surprise — the outputs are fully isolated, so you need to supply a ground and power to the load, it worked immediately to drive my test solenoid. Since it’s Arduino powered, it’s easy to control using the standard Arduino API commands.

    Having a display is a really nice plus, but it would be even better if there were a few pushbuttons. However, those are easy enough to add with the many digital inputs. I put together a demo platform with a power supply and a pushbutton mounted to a short piece of DIN rail and the PLC screwed directly to a panel. For output, I have a small stacklight that I converted from incandescent lighting to LED.

    I ran a test with a basic one-shot timer having a pushbutton input on X0 and an output on Y0. Here’s the code.

    // Project sponsor: N/A
    // Email: sales@cedarlakeinstruments.com
    // Creator: Cedar Lake Instruments LLC
    // Date: January 2023
    //
    // Description:
    // Demonstrate one-shot logic with Arduino
    // Tested on ZanhorDuino board
    // 
    // Arduino pins
    // 9 - Digital trigger input. Pull LOW to trigger one shot
    // 8 - One shot output (goes HIGH for one shot time)
    //
    //
    // Test program for ZanhorDuino PLC
    // NPN outputs are optically isolated so need their own V+ & GND connections
    //
    
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    
    // set the LCD address to 0x27 for a 16 chars and 2 line display
    LiquidCrystal_I2C lcd(0x27,16,2);  
    
    // ********** U S E R  A D J U S T M E N T S ********************
    // One shot time in milliseconds
    const int DELAY_MS = 6000;
    // **************************************************************
    
    const int INTERVAL_MS = 100;
    int _timeout = 0;
    const bool OUTPUT_ON = false;
    const bool OUTPUT_OFF = true;
    
    // X0 is input
    const int TRIGGER_PIN = 8;
    
    // Y0 is output
    const int OUT_PIN = 9 ;
    
    
    void setup() 
    {
        pinMode(TRIGGER_PIN, INPUT_PULLUP);
        pinMode(OUT_PIN, OUTPUT);
        digitalWrite(OUT_PIN, OUTPUT_OFF);
    
        lcd.init();
        // Print a message to the LCD.
        lcd.backlight();
        printStatus(DELAY_MS, LOW);   
    }
    
    void loop() 
    {
        // One shot triggers on high->low transition of TRIGGER pin
        while (digitalRead(TRIGGER_PIN) == HIGH)
        {
            // Hold while pin not pressed
        } 
    
        // Activate output and start timing
        _timeout = DELAY_MS;
        digitalWrite(OUT_PIN, OUTPUT_ON);   
    
        // Hold output High until timeout 
        while ((_timeout-= INTERVAL_MS) > 0)
        {
            printStatus(_timeout, HIGH);
            delay(INTERVAL_MS);
        }
    
        // Turn output off
        digitalWrite(OUT_PIN, OUTPUT_OFF);
        // Update display
        printStatus(DELAY_MS, LOW);
    }
    
    // Prints remaining time and output status
    void printStatus(int t, bool state)
    {
        char buffer[17];
        // Pad to 16 characters: 12 for text (left-justified) 
        // and 4 for time (right-justified)
        sprintf(buffer,"%-12s%4d","TIME:",t/1000);
        lcd.setCursor(0,0);
        lcd.print(buffer);
        
        lcd.setCursor(0,1);
        state ? lcd.print("Output ON ") : lcd.print("Output OFF");
    }

    This works nicely. Press the pushbutton and the output turns on and the display shows a countdown in seconds until the output is back off.

    When I have some more time, I’ll take a look at the analog inputs!




    If you’d like to subscribe to this blog, please click here.