Skip to content

Instantly share code, notes, and snippets.

@av
Last active January 12, 2025 02:06
Show Gist options
  • Save av/684239bd3a5fd706959aca2dda1d6b7a to your computer and use it in GitHub Desktop.
Save av/684239bd3a5fd706959aca2dda1d6b7a to your computer and use it in GitHub Desktop.
Cardputer Replies

I can help you create a darkroom timer using the M5Stack Cardputer and a relay unit. This will allow you to control an enlarger or other darkroom equipment. Here's a basic implementation:

#include <M5Cardputer.h>

// Pin definitions
const int RELAY_PIN = 38;  // Adjust this according to your relay connection
const int DEFAULT_TIME = 10;  // Default time in seconds

// Global variables
int timerSeconds = DEFAULT_TIME;
bool timerRunning = false;
unsigned long startTime = 0;

void setup() {
  M5Cardputer.begin();
  M5Cardputer.Display.setRotation(1);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);  // Ensure relay starts OFF
  
  displayMenu();
}

void displayMenu() {
  M5Cardputer.Display.clear();
  M5Cardputer.Display.setCursor(0, 0);
  M5Cardputer.Display.printf("Darkroom Timer\n");
  M5Cardputer.Display.printf("Time: %d sec\n", timerSeconds);
  M5Cardputer.Display.printf("\nControls:\n");
  M5Cardputer.Display.printf("↑/↓: Adjust time\n");
  M5Cardputer.Display.printf("ENTER: Start/Stop\n");
  M5Cardputer.Display.printf("ESC: Reset\n");
}

void loop() {
  M5Cardputer.update();
  
  if (M5Cardputer.Keyboard.isPressed()) {
    Keyboard_Class::KeysState key = M5Cardputer.Keyboard.keysState();
    
    if (!timerRunning) {
      // Adjust time when timer is not running
      if (key.key == '=') {  // Up arrow
        timerSeconds++;
        displayMenu();
      } else if (key.key == '-') {  // Down arrow
        if (timerSeconds > 1) {
          timerSeconds--;
          displayMenu();
        }
      } else if (key.key == KEY_ENTER) {  // Start timer
        timerRunning = true;
        startTime = millis();
        digitalWrite(RELAY_PIN, HIGH);  // Turn ON relay
      }
    }
    
    if (key.key == KEY_ESC) {  // Reset
      timerRunning = false;
      timerSeconds = DEFAULT_TIME;
      digitalWrite(RELAY_PIN, LOW);  // Turn OFF relay
      displayMenu();
    }
  }
  
  if (timerRunning) {
    unsigned long elapsed = (millis() - startTime) / 1000;
    int remaining = timerSeconds - elapsed;
    
    M5Cardputer.Display.clear();
    M5Cardputer.Display.setCursor(0, 0);
    M5Cardputer.Display.printf("Time remaining:\n%d sec", remaining);
    
    if (remaining <= 0) {
      timerRunning = false;
      digitalWrite(RELAY_PIN, LOW);  // Turn OFF relay
      M5Cardputer.Display.clear();
      M5Cardputer.Display.printf("Done!\n");
      delay(1000);
      displayMenu();
    }
  }
}

To use this with your setup:

  1. Hardware Setup:

    • Connect the relay unit to the Cardputer
    • Connect your enlarger or other equipment to the relay
    • Make sure to verify the correct pin number for your relay connection
  2. Features:

    • Use up/down arrows to adjust exposure time
    • Press ENTER to start the timer
    • Press ESC to reset
    • The relay will turn ON when the timer starts and OFF when it completes
    • Display shows remaining time during countdown
  3. Customization options you might want to add:

    • Add a beeper for end-of-exposure notification
    • Save preferred times to memory
    • Add multiple preset times
    • Add f-stop timing calculations

Would you like me to modify any part of this code or add additional features for your specific needs?

Certainly! The Cardputer is a compact, programmable device that can be used for various projects, including building a darkroom timer. By connecting a relay unit to the Cardputer, you can control the power to your darkroom equipment (e.g., enlarger or safelight) with precise timing.

Here’s a step-by-step guide to help you configure the hardware and write a program for your darkroom timer:


Hardware Setup

  1. Cardputer: This is your main microcontroller unit.
  2. Relay Module: A relay module will act as a switch to control the power to your darkroom equipment.
  3. Power Supply: Ensure the Cardputer and relay module are powered appropriately.
  4. Connections:
    • Connect the relay module's control pin (IN) to a GPIO pin on the Cardputer (e.g., GPIO 5).
    • Connect the relay module's VCC to the Cardputer's 5V or 3.3V pin (depending on the relay module's requirements).
    • Connect the relay module's GND to the Cardputer's GND.
    • Connect the darkroom equipment to the relay's NO (Normally Open) and COM (Common) terminals.

Software Setup

You’ll need to write a program for the Cardputer to control the relay module. Below is an example program written in MicroPython (a common language for microcontrollers like the Cardputer):

Code: Darkroom Timer

from machine import Pin
import time

# Pin configuration
RELAY_PIN = 5  # GPIO pin connected to the relay module
relay = Pin(RELAY_PIN, Pin.OUT)

# Timer settings
EXPOSURE_TIME = 10  # Exposure time in seconds
DELAY_TIME = 2      # Delay before turning off (optional)

def darkroom_timer():
    print("Starting darkroom timer...")
    
    # Turn on the relay (activate the equipment)
    relay.on()
    print("Relay ON - Equipment powered")
    
    # Wait for the exposure time
    time.sleep(EXPOSURE_TIME)
    
    # Turn off the relay (deactivate the equipment)
    relay.off()
    print("Relay OFF - Equipment powered down")
    
    # Optional delay before ending
    time.sleep(DELAY_TIME)
    print("Timer complete!")

# Run the timer
darkroom_timer()

How It Works

  1. The program initializes the relay pin as an output.
  2. When the timer starts, the relay is turned on, powering the darkroom equipment.
  3. The program waits for the specified exposure time (e.g., 10 seconds).
  4. After the exposure time elapses, the relay is turned off, cutting power to the equipment.
  5. An optional delay can be added before the program ends.

Customization

  • Adjust Exposure Time: Change the EXPOSURE_TIME variable to your desired exposure duration.
  • Add User Input: Use buttons or a keypad to allow the user to input the exposure time.
  • Multiple Timers: Add multiple timers for different processes (e.g., development, stop bath, fixing).

Example with User Input

If you want to allow the user to input the exposure time, you can modify the program as follows:

from machine import Pin
import time

# Pin configuration
RELAY_PIN = 5
relay = Pin(RELAY_PIN, Pin.OUT)

def get_exposure_time():
    try:
        exposure_time = int(input("Enter exposure time (seconds): "))
        return exposure_time
    except ValueError:
        print("Invalid input. Please enter a number.")
        return get_exposure_time()

def darkroom_timer():
    exposure_time = get_exposure_time()
    print(f"Starting timer for {exposure_time} seconds...")
    
    relay.on()
    print("Relay ON - Equipment powered")
    
    time.sleep(exposure_time)
    
    relay.off()
    print("Relay OFF - Equipment powered down")
    print("Timer complete!")

# Run the timer
darkroom_timer()

Testing

  1. Upload the program to your Cardputer.
  2. Connect the relay module and darkroom equipment.
  3. Run the program and observe the relay switching on and off according to the timer.

Safety Notes

  • Ensure all electrical connections are secure and insulated to prevent short circuits.
  • Use a relay module rated for the voltage and current of your darkroom equipment.
  • Test the setup with low-power devices before connecting high-power equipment.

Let me know if you need further assistance!

Cardputer is a fascinating device, and building a darkroom timer with a relay unit sounds like an exciting project. To help you configure and write a program, I'll need more information. Please provide the following details:

  1. Cardputer model: Which Cardputer model are you using?
  2. Relay unit specifications: What is the type and model of the relay unit you're planning to use? How many channels does it have?
  3. Darkroom timer requirements: What are the specific requirements for your darkroom timer? For example:
    • What is the range of timer intervals you want to achieve (e.g., 1-60 minutes)?
    • Do you need to control multiple lights or devices in the darkroom?
    • Are there any specific features you want to include, such as a countdown display, alarm, or repeat mode?
  4. Input and output connections: How will you connect the Cardputer to the relay unit and the lights or devices in the darkroom?
  5. Programming experience: Do you have any prior experience with programming or using the Cardputer's development environment?

Once I have this information, I'll be happy to help you configure your Cardputer and write a program to create a functional darkroom timer with your relay unit.

I can definitely guide you through the process of building a darkroom timer using a Cardputer, Relay Unit, and some programming!

Here's a breakdown of the components and steps involved:

Components:

  • Cardputer: A small, single-board computer that will be the brain of your timer. You'll need to choose a model with sufficient processing power and connectivity (e.g., ESP32 or Raspberry Pi Pico).
  • Relay Unit: This unit will control the electrical switching for your darkroom equipment. Choose one compatible with your Cardputer and capable of handling the current requirements of your enlarger or other devices.
  • Push Buttons: You'll need a couple of buttons: one to start/stop the timer and another to set the desired time.
  • Display (optional): An LCD or LED display can be helpful for visualizing the remaining time.

Software & Programming:

  1. Choose Your Programming Language: Python is a popular choice for Cardputer projects due to its simplicity and extensive libraries. Other options include C/C++ or MicroPython.

  2. Cardputer Setup:

    • Flash Firmware: Follow the instructions on your Cardputer's documentation to flash the appropriate firmware onto the device. This will enable it to run your chosen programming language.
    • Connect Components: Connect your relay unit, push buttons, and display (if using) to the appropriate GPIO pins on your Cardputer following its pinout diagram.
  3. Write Your Program: Here's a basic Python code structure to get you started:

import time
# Import any necessary libraries for your specific hardware (e.g., RPi.GPIO for Raspberry Pi)

# Define GPIO pins for buttons and relay
start_button_pin = 17
set_time_button_pin = 27
relay_pin = 4

# Initialize GPIO pins
# ... (add code to set pin modes, etc.)

while True:
    if start_button_pin == 0:  # Button pressed
        # Start timer logic here
        elapsed_time = 0
        target_time =  # Get target time from user input or default value

        while elapsed_time < target_time:
            time.sleep(1)
            elapsed_time += 1

            # Update display (if using) with remaining time

        # Turn on relay when timer reaches zero
        relay_pin = 1  # Set pin HIGH to activate relay

    elif set_time_button_pin == 0:
        # Logic to set the target time
        pass 

Explanation:

  • Initialization: This section sets up your GPIO pins for input and output. Refer to your Cardputer's documentation for specific pin assignments.
  • Main Loop: The while True loop keeps the program running indefinitely.
  • Button Checks: It checks if the start or set time buttons are pressed and executes the corresponding logic.
  • Timer Logic: When the start button is pressed, a timer begins counting up until it reaches the desired target time. You'll need to implement code to handle getting the target time (either from user input or a default value).
  • Relay Control: Once the timer reaches zero, the relay pin is set HIGH to activate your darkroom equipment.

Important Considerations:

  • Safety First: When working with electricity, always prioritize safety. Use insulated tools and double-check all connections.
  • Current Ratings: Ensure that your relay unit can handle the current draw of your darkroom devices. Exceeding the relay's rating can lead to damage or fire hazards.
  • Debugging: Start with simple tests and gradually build up complexity. Use debugging techniques like print statements or a logic analyzer to identify any issues in your code.

Additional Features (Optional):

  • Display: Add an LCD or LED display to show the remaining time clearly.
  • User Interface: Create a more interactive user interface with multiple buttons for different exposure times, timers, etc.
  • Sound Alerts: Trigger a buzzer or sound alert when the timer reaches zero.

Let me know if you have any further questions or want help with specific code examples based on your chosen Cardputer model and relay unit.

A darkroom timer sounds like an interesting project!

A Carduino (Arduino-based) computer with a relay unit is a great platform for building a timer. I'd be happy to help you configure the hardware and write a program.

Hardware Requirements:

  1. Carduino (e.g., Arduino Uno or similar): This will be our brain for the project.
  2. Relay Unit: You'll need a relay module that can switch on/off a load (e.g., a light, motor) based on digital signals from the Carduino.
  3. Power Supply: Ensure your Carduino and relay unit have a stable power supply.

Software Requirements:

  1. Arduino IDE: Download and install the Arduino Integrated Development Environment (IDE) to write and upload programs to your Carduino.
  2. Relay library: We'll need a library to control the relay module.

For this example, I'll assume you're using an Arduino Uno with a 4-channel relay module like the SRD-05VDC-SL-C.

Wiring Diagram:

Connect the relay module to your Carduino as follows:

  • Relay module's VCC pin to Carduino's 5V pin
  • Relay module's GND pin to Carduino's GND pin
  • Relay module's IN1-4 pins to Carduino's digital pins (e.g., D2, D3, etc.)

Program Example:

const int relayPin = 2; // Pin connected to the first relay output

void setup() {
  pinMode(relayPin, OUTPUT);
}

void loop() {
  digitalWrite(relayPin, HIGH); // Turn on the relay (connected to a light bulb)
  delay(60000); // Wait for 1 minute
  digitalWrite(relayPin, LOW); // Turn off the relay
  delay(300000); // Wait for 5 minutes
}

This program will turn on the relay connected to the light bulb every minute and keep it on for 6 minutes. You can adjust the timing as needed.

Configuring the Program:

To make this a darkroom timer, we'll need to add features like:

  1. Multiple exposure modes: Offer options for single exposures, multiple exposures, or continuous exposure.
  2. Timer setting: Allow users to set the duration of each exposure and the number of exposures.
  3. Darkroom safety features: Add warnings or alarms when the timer is about to expire.

We can use the Arduino IDE's built-in functions to create a simple user interface using buttons and LEDs.

Next Steps:

  1. Research and understand the relay library you'll need to control the relay module.
  2. Set up your Carduino with the relay unit and power supply.
  3. Write additional code to implement the features mentioned above.
  4. Test and refine the program as needed.

If you have any questions or need further assistance, feel free to ask!

Certainly! A "cardputer" sounds like an unusual term; I believe you might be referring to using a microcontroller or single-board computer (SBC) such as Arduino, Raspberry Pi, or ESP32 for your project. Additionally, the "relay unit" is typically used to switch higher voltages or currents than the microcontroller can handle directly. For this example, let's assume you're working with an Arduino and a relay module.

A darkroom timer could be useful in photography where precise timing is necessary when developing photos. Here’s how you might set up such a project:

Components Needed

  1. Arduino Microcontroller (e.g., Uno, Nano)
  2. Relay Module
  3. Pushbuttons or Switches for Input
  4. LEDs for Status Indication (optional)
  5. Breadboard and Jumper Wires

Objective

To create a timer that can be set to specific times (e.g., 1 minute, 2 minutes, etc.) using push buttons and will activate the relay after the specified time has elapsed.

Wiring Diagram

  • Connect your relay module according to its documentation. Typically, it would have an input pin connected to one of Arduino's digital pins.
  • Use two or more pushbuttons connected to different digital pins on the Arduino for setting the timer duration (e.g., 1 minute and 2 minutes).
  • If you are using LEDs:
    • One LED can indicate that the relay is active.
    • Another LED could be used as a heartbeat or status indicator.

Program Code

Here's a simple program in Arduino IDE to achieve this:

const int buttonPin_1min = 2;   // Pin connected to minute switch
const int buttonPin_2min = 3;   // Pin connected to two-minute switch
const int relayPin = 4;         // Relay control pin

unsigned long startTime;
int selectedTime = 0;           // Timer duration in seconds (1 minute = 60, 2 minutes = 120)

void setup() {
  pinMode(buttonPin_1min, INPUT_PULLUP);
  pinMode(buttonPin_2min, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);

  Serial.begin(9600);           // For debugging
}

void loop() {
  if (digitalRead(buttonPin_1min) == LOW && selectedTime == 0) { // If minute button is pressed and no time has been set yet.
    startTime = millis();
    selectedTime = 60 * 1000;    // Set timer for 1 minute
    Serial.println("1 Minute Timer Started");
  }
  
  if (digitalRead(buttonPin_2min) == LOW && selectedTime == 0) { // If two-minute button is pressed and no time has been set yet.
    startTime = millis();
    selectedTime = 60 * 2 * 1000; // Set timer for 2 minutes
    Serial.println("2 Minute Timer Started");
  }

  if (selectedTime != 0) {
    unsigned long currentMillis = millis();

    if ((currentMillis - startTime) >= selectedTime) { 
      digitalWrite(relayPin, HIGH);  // Activate relay after selected time
      Serial.println("Timer Done!");
      
      delay(2000);                    // Wait for two seconds before resetting the timer.
      selectedTime = 0;               // Reset timer duration
    }
  }

}

Explanation of Code:

  1. Setup: Initializes pins and starts serial communication for debugging purposes.
  2. Loop:
    • Checks if one-minute or two-minute buttons are pressed, setting startTime to the current time and selectedTime to either 60 seconds (1 minute) or 120 seconds (2 minutes).
    • If a valid timer has been set (selectedTime != 0), it checks how much time has elapsed since startTime.
    • Once the elapsed time equals selectedTime, the relay is activated, and an LED could indicate this state.
    • After the specified delay to let the user know the action has taken place (or for processing purposes), resets the timer (selectedTime).

Safety Note

  • Make sure you understand how relays work with your specific application. Misuse can lead to damage of equipment or injury.
  • Always ensure that the relay module is properly insulated and secured to prevent accidental contact.

Feel free to modify this code based on your exact requirements, such as adding more timer settings or changing timing durations!

I would like to use cardputer with relay unit to build darkroom timer can you help me configure it and write a program?

Sure, I can help you set up a darkroom timer using a Cardputer (assuming it's a small microcontroller-based computer or dev board) paired with a relay unit. Here’s a step-by-step guide to help you configure and write the program:

Step-by-Step Guide

1. Gather Components:

  • Cardputer (microcontroller): Make sure it has GPIO pins which will connect to the relay unit.
  • Relay Module: Choose one that's compatible with the voltage levels of your Cardputer. Typically, relays take 3.3V or 5V input.
  • Timer: Software-based on Cardputer.
  • Photography Accessories: Lights, stop button, etc.
  • Power Supply: To power the relay module and darkroom lights if needed.

2. Connect the Relay Module:

  • Input Signal (e.g., GPIO Pin) of the Cardputer → Control Pin of the Relay Module.
  • Ground (GND) of the Cardputer → Ground (GND) of the Relay Module.
  • Load (Darkroom Light or other equipment) → NO (Normally Open) or NC (Normally Closed) pin and Common Pin of the Relay Module.
  • VCC of the Relay: Make sure it’s powered appropriately, usually 3.3V or 5V depending on the relay module.

3. Set Up the Cardputer:

  • Download and install the necessary software and libraries if not already done.
  • Write and upload the software for controlling the relay.

4. Write the Program:

Below is a simple example in Python assuming you are using a microcontroller like a Raspberry Pi with a compatible setup.

import RPi.GPIO as GPIO
import time

# Relay control pin configuration
relay_pin = 18  # GPIO18

# Setup GPIO mode and relay pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay_pin, GPIO.OUT)

# Function to turn lights on
def turn_lights_on():
    GPIO.output(relay_pin, GPIO.LOW)  # Depending on relay module, LOW or HIGH might activate it

# Function to turn lights off
def turn_lights_off():
    GPIO.output(relay_pin, GPIO.HIGH) # Depending on relay module, HIGH or LOW might deactivate it

# Main function for the timer
def darkroom_timer(seconds):
    turn_lights_on()
    print(f"Lights on for {seconds} seconds.")
    time.sleep(seconds)
    turn_lights_off()
    print("Lights off.")

if __name__ == "__main__":
    try:
        # Set your desired timer duration in seconds
        duration = 30  # Example: 30 seconds
        darkroom_timer(duration)
    finally:
        GPIO.cleanup()

Explanation of the Code:

  • GPIO Setup: Configuring the GPIO pin connected to the relay.
  • Relay Control: turn_lights_on and turn_lights_off control the relay for turning lights on and off.
  • Timer Function: darkroom_timer function makes the lights turn on for a specified duration then turns them off.
  • Main Execution: The if __name__ == "__main__": block is the main section that executes when the script runs, allowing you to set a different duration.

5. Testing:

  • Make sure everything is connected correctly.
  • Run the script and observe if the lights turn on and off as per the timer.

6. Advanced Features:

If needed, you can add more features such as:

  • A stop button to manually stop the timer.
  • Input to set the timer duration dynamically.
  • Logging the on/off times.
  • Integrate with a photoresistor to automatically detect changes in light levels.

Hope this helps you with your darkroom timer project! If you face any specific issues or need further assistance, feel free to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment