Can someone help me with some firmware please?

yup, if I wasn't such a tightwad and obsessed with doing (most) things myself, that's exactly what I'd do :)

You say you are obsessed with doing things yourself, yet you are asking for help--not to debug code you've written or attempted to write, but basically to have someone make all of the modifications for you then hand you the code.

It seems like a bit of a contradiction. Am I missing something?

well I also wanted to modify just a bit here and bit there, but few months later I find myself writing new firmware for attiny85 because attiny13’s 1k is not enough :slight_smile:

i do have modified star momentary with moving forward and backwards through modes with short/long press. Perhaps you can start from there and modify it just a bit more to suit you.

RMM has said it nicely, so I’m just going to second his question.

Of course my advice is to purchase what you need. There are at least 2 good places to purchase DIY stuff for what you need: DrJones or TaskLED.

so that's a no then?

The contradiction is that I feel like I've helped a lot of people on here and I'm completely stumped by something I find very difficult, so I'm asking for help. I thought that as part of a larger community people would be willing to offer their help and by extension, help others that are in a similar situation. I thought that by getting a lift up and over that hump of understanding, which I just don't have to mental capacity to manage by myself, I would be able to continue on and perhaps contribute something similar myself.

It's like someone saying - I really need something made with a thread and I just can't figure it out myself, can someone make one for me to get me over my immediate need and show me so that I can teach myself, then perhaps figure it out and teach others? Or should I just be told - go do it yourself or pay to get it made?

I'm not asking anyone to write something from scratch (although you all seem fine with other people doing that for other members - did I phrase my request poorly?) more apply some tweaks that I don't know how to do to existing code. I've spent months poring through publicly available firmwares and I still don't have a clue how to do what I need. The irony is that it's taken weeks (if not months) to find the time (and courage!) to make this request. Sure I can buy stuff, but that would take money and that's something I don't have much to spare right now, for various reasons.

vex_zg, that would be a great help, thank you

We all like to share here, and we all like to help. It's a big part of why we're here. I like helping other people, and I benefit from what others post as well. I hope I am not coming across the wrong way, because I have certainly benefitted and learned a lot from everyone on this forum. There is no way I could have thought up or figured out all of the things I use and build on an daily basis on my own. I owe a lot of my knowledge and success to many here who have shared their thoughts, experiments, failures, and who have helped me with my various projects along the way.

There is nothing wrong with asking for help, but there is a big difference between asking for help with a project and asking for a handout. I'm not saying that asking for a handout is inherently wrong, because there are some here that like to take on difficult tasks both as a challenge to themselves and to help others, but you've got to be clear about what you are looking for. I think that is clear now.

There are some on here who would like to help you, I'm sure, but what you asked for is a pretty big undertaking and what you are looking for is complicated and very particular to you. Even for a competent coder, it is something that would take at least several hours worth of coding and debugging to get it running right.

It is a different story to say "I want to accomplish this specific task. This is the code I'm working with, this is what I've tried, this is where I'm stuck". Or, "I would like to add a specific feature to this firmware, can you help me? Where do I start?" If your goal really is to learn how to do it yourself, this is how it's done. I may be able to glean something from copying the answers to another student's math examination, but I won't truly learn it until I do it myself. Teachers, tutors, books, and other students are there to help with examples and to answer questions when you get stuck, but at the end of the process you will have learned it through going through the motions yourself.

What you asked for came across to me as this "I want two complex custom firmwares written for my very specific application. I have an immediate need for this firmware and need it fast. I am not willing to pay, but of course you can publish it if you'd like."

In summary, if your goal is to learn, we are always here to help with that, but it may not be fast or easy. Show us what you've tried and where you're stuck at.

that's fair enough RMM and I can see where I came across wrong. The trouble is I have no idea where to start. I've spent ages looking at Toykeeper's cool rear bike light firmware for clicky lights and at JonnyC's star momentary and I've no idea how to get from one to the other. It's like needing something translated but having to learn a whole language first. I don't even know what questions to ask. I even downloaded the ATtiny manual, but it makes no sense to me at all. Perhaps you're right, I should just give up and buy something, but neither of the offerings I particularly want (I bought one of DrJones' mobydrv drivers after helping him design the firmware and have never got it working right and I've used a ton of the Taskled drivers but can't afford them now).

I appreciate the value of learning by doing, after all I'm a professor so it's something I do every day :) I just can't seem to get beyond the basic electronics in the time I have available (couple of hours a week, shared with everything else I want to do).

So I'll see if Vex_zg's FW will do the trick and leave the other one as is.

BTW, the fact that DrJones has sold a few (how many we'll never know) of those mobydrv drivers, mostly on mountainbiking forums, and that Toykeeper is working on some firmware for other cyclists suggests that this isn't just for my benefit. That's just my perspective though.

Have a look at this minimalistic firmware by DrJones. It is well commented, so you should be able to get started: MiniDrv - simple firmware (source code)

I have to agree with the others… Writing firmware with semi-complex features takes time. People here are very helpful and share knowledge, but to be frank: you are asking for too much.

Nice try anyway. I might try offering to trade some hardware for the work. I don’t see a problem with bartering.

Thanks MikeC, it's obviously clear that I'm asking for too much given the responses although if I thought that any of the things I asked for were too much I wouldn't have asked for them. I was going by the responses others have had for similar requests (and the help I have had with other things) but clearly I am mistaken. I get the message.

I'll see what I can do with the firmwares posted up by others already and leave it at that.

I myself modified STAR momentary to do something similar to what you are asking for. Read this.

Edit: A link to a newer version of the firmware can be found here.

ToyKeeper mentioned that she has something similar in her repository.

I have since added a nice ramping feature with 19 brightness levels.

The fun and challenge of flashlight FW coding is to take someone else’s code that works but not exactly like what you want and then tweaking it to do what you want. The trap is that you are never completely happy with the UI and run out of code space and wishing that you can get another 1 KiB to add that one extra feature to make the perfect UI.

Once you get the firmware to do what you want, please return the favor and share the code with us.

thanks for the links dthoang, much appreciated. I've chatted with Selene a bit about the rear bike light code she's working on for clicky lights, but she's got a lot of other things on the boil right now.

I promise to share my progress, it'll most likely be a couple of years though.

Hi Matt, I don't work with AVR much so it would be an ordeal to write out the whole thing, but here's something that should help you get moving if you'd like to learn to do it yourself. Start by looking at my example code in this post: https://budgetlightforum.com/t/-/26378 That implements a basic light on ATTiny10 that uses a momentary switch. It should be easy to port it to ATTiny13 or another microcontroller. To add the strobe pattern you want, here's my method which uses a state machine and keeps everything clean, organized, and gives the processor plenty of time to perform other tasks (monitoring the button, voltage, etc.). Each of these sections go in a different spot in the code example linked above, it should be clear where each one belongs.

//add strobe to mode list, increase number of modes. 
//could make strobe and off the only modes if desired
unsigned char mode;
enum mode{
    max=0,
    med=1,
    low=2,
    strobe=3,
    off=4,
};
#define max_mode 4
//add a variable to maintain the state of the strobe pattern
unsigned char strobe_state;
//add a variable to time out the strobe pattern
unsigned int strobe_timer;
//add the countdown timer to the interrupt
if(strobe_timer){strobe_timer--;}
//add the strobe handler to the main loop
        if(state==strobe){  //only take action if in strobe mode
            if(strobe_timer==0){    //only take action if the last state finished
                strobe_state++;     //advance to the next state
                strobe_state&=0b00000011;   //limit the state value to four states
                switch(strobe_state){       //jump to the appropriate state
                    case 0:                     //state 0 - the long low time
                        pwm = 64;               //25%, change as desired
                        strobe_timer = 1000;    //1000ms, or one second of low output, change as desired
                        break;                  //done with this task
                    case 1:                     //state 1 - the first high time
                        pwm = 255;              //100%, change as desired
                        strobe_timer = 40;      //the blink duration. 40ms. change as desired
                        break;
                    case 2:                     //middle low period
                        pwm = 64;
                        strobe_timer = 80;      //80ms duration
                        break;
                    case 3:                     //second blink
                        pwm = 255;
                        strobe_timer = 40;
                        break;
                }
            }
        }

thank you tterev3, that is awesome, totally awesome and exactly what I was looking for! I'll find a basic momentary firmware (like minimo that has everything else I need) and stick it in there to see how it works.

If you add this to a different program instead of my example, be sure you have a timer source that can decrement the timer variable in the background. The 1kHz interrupt is something I always include in my code but it won’t be present in everyone’s

thank you, I was wondering about compatibility. I'll go read some of the others and get a sense of how they do things. Right now I'm must trying to learn and understand enough to be able to ask the right questions!

tterev3, thank you for sharing. I am not good enough to help much with firmware, although I have stumbled and fumbled my way into a few successful small modifications.

Matt,

I glanced back at your other request and realized it would be pretty simple to add to my ATTiny10 example as well, so here are the changes you'd need for that, still referencing the base code I posted here

//add a variable to time button presses
unsigned int press_timer;
//change debounce routine to:
    //time button presses and
    //throw new press flag after switch is released instead of after it is pressed
void debounce(void)
{
    static char port_copy=0xff;
    #define switch_mask 0b00000001  //this selects PB0 as the switch
if((PINB&switch_mask)==port_copy)   //if the current state matches previous state
{
    if(--switch_count==0)   //count down samples. if 10 consecutive samples matched
    {
        switch_count=10;    //reset sample counter
        if(PINB&switch_mask){   //if the state is high,
            if(pressed) new_press=1; //if the last state was pressed, the switch was just released. indicate new complete press
            pressed=0;   //indicate switch is up
        }
        else        //else switch is down. check for new press
        {
            //if(pressed==0) new_press=1;   //if last state of pressed was 0, this is a new press
            if(pressed==0) press_timer=0; //restart the timer if the switch just went down
            pressed=1;  //switch is now down
            press_timer++; //count up time while switch is held down
        }
    }
}
else    //state doesn't match,
{
    switch_count=10;    //reset sample counter
    port_copy=(PINB&switch_mask);   //get new sample
}

}

//change mode change hanlder in main loop to distinguish between press lengths
        if(new_press){
            new_press=0;
            if(press_timer<30){ //if held less than 300ms (my time limit, change if desired)
                mode++; //increment mode
                if(mode>max_mode) mode=0;    //limit mode variable to available values
            }
            else if(press_timer<60){ //if held >300ms and <600ms,
                mode--; //decrement mode
                if(mode>max_mode) mode=mode_max; //limit mode variable to available values
            }
            else    //else, it was held a long time
                mode=off;
            initialize_mode();
        }

thank you tterev3, much appreciated! I had an idle thought in lab that I should go find a guide to simple AVR programming so that I can learn exactly why things are written the way they're written. It's interesting to see how different people come to the same function in different ways too (even if I don't understand why). Nothing doing for me tonight though, my mind is blasted and it's "watch a film with the wife" evening :)