Contribute
Register

Kiwi's Next Project - iMac G5

Status
Not open for further replies.
Excellent Kiwi, this is ramping up into something great!


Cheers!
 
Kiwi,
Thanks for your hints. :thumbup: I've ordered an Arduino Leonardo and will do some tests. My actual Picaxe project is to mod a duplo locomotive for our boys. It will be equipped with an IR remote for the following functions:
-Drive forward and backward with 7 speed steps
-Different headlights, depending on the drive direction
-Horn
-Steam locomotive sound in accordance with the drive speed

Works fine so far on the breadboard.

MacTester
 
Kiwi,
Thanks for your hints. :thumbup: I've ordered an Arduino Leonardo and will do some tests. ...
MacTester
Welcome to the A club, would be good to get some feedback once you have finished.

One more thing about SimpleTimer that I have not posted thus far.

I enhanced the library to allow a flexible timer behaviour where the number of iterations, and the frequency is controlled by the return value of the function itself, rather than when the timer is started. i.e. The return value of the function call defines the time to wait for next call, value of 0 indicates to stop the timer.

The example below shows how I intend to use it to control an output signal over time. This allows you to replace code, that has arbitrary delay() statements between blocks of code, although this is just one way of using it.

Code:
void newMethod() {
  
  // setup a timer to press the button  
  timer.setVariableTimer(powerButtonCallback);

}

long powerButtonCallback(int callNumber) {
  
  if (callNumber ==0) {
    // delay 1000ms
    return 1000;

  } else if (callNumber ==1) {
    // output high value for 200ms
    digitalWrite(NUC_POWER_SWITCH_POUT,HIGH);
    return 200;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(NUC_POWER_SWITCH_POUT,LOW);
    return 0;
  }
}

void oldWayOfDoingIt() {
  
    delay(1000);
    digitalWrite(NUC_POWER_SWITCH_POUT,HIGH);
    delay(200);
    digitalWrite(NUC_POWER_SWITCH_POUT,LOW);

}
I have submitted the code back to the author but website not been updated, so attached the newer library. Hope it helps.

EDIT : I removed the attachment to this thread as the code is now hosted on GitHub
https://github.com/kiwisincebirth/Arduino/tree/master/libraries/SimpleTimer


Kiwi
 
Kiwi,

Thanks again for your help. I've tried your modified SimpleTimer library. It works as long as the time values are the same for all 3 LED. But it's freaking out, if every LED has different time values. Any thoughts?

Code:
// Include the following Libraries-------------------------------------
#include <SimpleTimer.h>  //SimpleTimer

// A general purpose timer, and some misc constants
SimpleTimer timer = SimpleTimer();

// Pin Assignments (constants)-----------------------------------------
const int LED_1 = 3;
const int LED_2 = 5;
const int LED_3 = 6;

// Define Variables----------------------------------------------------
//float currentPWM = 150; // Roughly equal to 3.3v
//float targetVOLT = 3.3; // current target voltage to match

void setup ( )
{
//This Commands are only executed during startup or reset--------------  
  // Declare Output Pins
  pinMode(LED_1,OUTPUT);
  pinMode(LED_2,OUTPUT);
  pinMode(LED_3,OUTPUT);
}

// This is the Main Loop-----------------------------------------------
void loop ( ) {
  timer.setVariableTimer(LED_1_Timer);
  timer.setVariableTimer(LED_2_Timer);
  timer.setVariableTimer(LED_3_Timer);
  timer.run();
}

//LED 1 Timer----  
long LED_1_Timer(int callNumber) {
  if (callNumber ==0) {
    // delay 1000ms
    return 1000;

  } else if (callNumber ==1) {
    // output high value for 200ms
    digitalWrite(LED_1,HIGH);
    return 200;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_1,LOW);
    return 0;
  }
}

//LED 2 Timer----
long LED_2_Timer(int callNumber) {  
  if (callNumber ==0) {
    // delay 1000ms
    return 1000;

  } else if (callNumber ==1) {
    // output high value for 100ms
    digitalWrite(LED_2,HIGH);
    return 100;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_2,LOW);
    return 0;
  }
}

//LED 3 Timer----
long LED_3_Timer(int callNumber) {  
  if (callNumber ==0) {
    // delay 1000ms
    return 1000;

  } else if (callNumber ==1) {
    // output high value for 50ms
    digitalWrite(LED_3,HIGH);
    return 50;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_3,LOW);
    return 0;
  }
}

EDIT: the following code works now.
Code:
// Include the following Libraries-------------------------------------
#include <SimpleTimer.h>  //SimpleTimer

// A general purpose timer, and some misc constants
SimpleTimer timer_1 = SimpleTimer();
SimpleTimer timer_2 = SimpleTimer();
SimpleTimer timer_3 = SimpleTimer();

// Pin Assignments (constants)-----------------------------------------
const int LED_1 = 3;
const int LED_2 = 5;
const int LED_3 = 6;

// Define Variables----------------------------------------------------
//float currentPWM = 150; // Roughly equal to 3.3v
//float targetVOLT = 3.3; // current target voltage to match

//This Commands are only executed during startup or reset--------------
void setup ( ) {  
  // Declare Output Pins
  pinMode(LED_1,OUTPUT);
  pinMode(LED_2,OUTPUT);
  pinMode(LED_3,OUTPUT);
}

// This is the Main Loop-----------------------------------------------
void loop ( ) {
  timer_1.setVariableTimer(LED_1_Timer);
  timer_2.setVariableTimer(LED_2_Timer);
  timer_3.setVariableTimer(LED_3_Timer);
  timer_1.run();
  timer_2.run();
  timer_3.run();
}

//LED 1 Timer----  
long LED_1_Timer(int callNumber) {
  if (callNumber ==0) {
    // delay 900ms
    return 900;
  } else if (callNumber ==1) {
    // output high value for 100ms
    digitalWrite(LED_1,HIGH);
    return 100;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_1,LOW);
    return 0;
  }
}

//LED 2 Timer----
long LED_2_Timer(int callNumber) {  
  if (callNumber ==0) {
    // delay 1900ms
    return 1900;

  } else if (callNumber ==1) {
    // output high value for 100ms
    digitalWrite(LED_2,HIGH);
    return 100;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_2,LOW);
    return 0;
  }
}

//LED 3 Timer----
long LED_3_Timer(int callNumber) {  
  if (callNumber ==0) {
    // delay 3900ms
    return 3900;

  } else if (callNumber ==1) {
    // output high value for 100ms
    digitalWrite(LED_3,HIGH);
    return 100;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_3,LOW);
    return 0;
  }
}

Another question: do you know, how the PWM frequency can be adjusted with the Leonardo controller? The PWM Frequency Library is not compatible with the ATmega32u4.

Thanks in advance
MacTester
 
Kiwi,

Thanks again for your help. I've tried your modified SimpleTimer library. It works as long as the time values are the same for all 3 LED. But it's freaking out, if every LED has different time values. Any thoughts?

EDIT: the following code works now.
Looking at you code the main issue is that you call setVariableTimer() every run through the main loop() function. This will create multiple "threads" invoking the same callback function, probably not what you want. Secondly SimpleTimer can handle 10 (can be increased) "threads", so you only need one of these to run the three timers in the example.

Below is some more example code showing the above changes with some more examples of the use of my enhancement. Also remember is nothing wrong with putting code in the main loop() function, so long as it is not long running code i.e. no delay() calls.

Code:
// Include the following Libraries-------------------------------------
#include <SimpleTimer.h>  //SimpleTimer

// A general purpose timer, and some misc constants
SimpleTimer timer = SimpleTimer();

// Pin Assignments (constants)-----------------------------------------
const int LED_1 = 3;
const int LED_2 = 5;
const int LED_3 = 6;

//This Commands are only executed during startup or reset--------------
void setup ( ) {  
  // Declare Output Pins
  pinMode(LED_1,OUTPUT);
  pinMode(LED_2,OUTPUT);
  pinMode(LED_3,OUTPUT);

  // Setup the BACKGROUND Timers (only needs to be done once) 
  timer.setVariableTimer(LED_1_Timer);
  timer.setVariableTimer(LED_2_Timer);
}

// This is the Main Loop-----------------------------------------------
void loop ( ) {

  if ( buttonWasPressed() ) {
    // when a button is pressed flash LED 3
    timer.setVariableTimer(LED_3_Timer);
  }

  timer.run();
}

//LED 1 Timer --- Shows How we can stop a timer at an arbitrary point in time 
long LED_1_Timer(int callNumber) {

  // do something useful every 1000ms
  // unless some external condition is met then stop the timer.
  if (somethingIsTrue()) return 0;

  return 1000;
}

//LED 2 Timer --- Shows how the frequency of the timer can can change.
long LED_2_Timer(int callNumber) {  

  // do something useful every 100 to 300 milliseconds

  // The period is variable and based on a sin function that 
  // cycles every 62.830 (pi*2*10) repetitions of the timer
  return sin(callNumber/10)*100+200
}

//LED 3 Timer --- An example of a one shot, where we pulse an output pin ONCE
long LED_3_Timer(int callNumber) {  
  if (callNumber ==0) {
    // delay 3900ms
    return 3900;

  } else if (callNumber ==1) {
    // output high value for 100ms
    digitalWrite(LED_3,HIGH);
    return 100;
    
  } else if (callNumber ==2) {  
    // reset output to low, and finish the timer
    digitalWrite(LED_3,LOW);
    return 0;
  }
}

Also see the following original SimpleTimer forum posting with examples of the standard functions and basic usage of SimpleTimer.

http://forum.arduino.cc/index.php?topic=38134.0

Kiwi,Another question: do you know, how the PWM frequency can be adjusted with the Leonardo controller? The PWM Frequency Library is not compatible with the ATmega32u4.

Thanks in advance
MacTester
I have not had any reason (yet) to change PWM frequency. There is quite a bit on the topic though, including some simple functions, and complete libraries. The Leonardo is a different chip to the main Arduino UNO, so some of the information is not applicable. Here are some links.

http://arduino.cc/en/Tutorial/PWM
http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM
http://playground.arduino.cc/Code/PwmFrequency
http://playground.arduino.cc/Main/TimerPWMCheatsheet
http://forum.arduino.cc/index.php/topic,117425.0.html
http://provideyourown.com/2012/arduino-leonardo-versus-uno-whats-new/
 
Hello, I'm a noob here but I used to build hackintoshes in the past before finally buying an Intel iMac. Lately I've found myself with one (maybe two) dead 17" iMac G5's and because of that I'm totally looking forward to this project!!! Thanks for sharing all of this information and keep it up, Kiwi! :thumbup::clap:
 
Hello, I'm a noob here but I used to build hackintoshes in the past before finally buying an Intel iMac. Lately I've found myself with one (maybe two) dead 17" iMac G5's and because of that I'm totally looking forward to this project!!! Thanks for sharing all of this information and keep it up, Kiwi! :thumbup::clap:
Thanks for your positive comments, be aware this may be slow going for a while, I am in process of moving, so workshop and tools have been packed up.

On a positive note. I have ordered the NUC today, so over Christmas will have some time to get OSX installed, not straight forward. At just over $700 AUD this isn't the cheapest, a low end Mac Mini isn't that much more expensive. I haven't seen the inside of a current Mac Mini, but potentially this could also be an option for this sort of a build.

NUC%20Order%20Details.png
 
So my D54250 i5 Haswel NUC arrived yesterday, and have installed the OS, based on posting by WonkeyDonkey, first main issue is the lack of audio support for motherboard.

EDIT: Initial Audio support is now in place, but not 100%, see WD's thread.

Power.

Have confirmed use of 12V Input PSU works. I actually used a power brick from a external HDD, rated at 12V 2A so only a 24W PSU. It ran fine, the PSU did warm up a little but noting too serious. Even ran CPU test for a short time maxing out the CPU just to push it a little bit.

Size

I am confident I can mount the NUC inside the iMAc, it will be a tight squeeze, the main issue will be finding a riGht angle SATA connector that doesn't add significant height to the motherboard. Open to any suggestions.

Next Steps

Next Steps are to pull the machine apart, and begin mounting the NUC, Unfortunately I am in transit and don't move into new house until Feb, so can't really begin this for the time being

:(
 
If you are unable to get the audio working on your NUC you might want to consider adding one of those OSX compatible USB Audio dongles into your build, I used one of those with my old Core 2 Duo Hackintosh as every time they did a new update for snow leopard it would always break my system. After turning off my onboard audio and removing the audio kext files it worked perfectly until it was retired.
 
If you are unable to get the audio working on your NUC you might want to consider adding one of those OSX compatible USB Audio dongles into your build, I used one of those with my old Core 2 Duo Hackintosh as every time they did a new update for snow leopard it would always break my system. After turning off my onboard audio and removing the audio kext files it worked perfectly until it was retired using the very inexpensive USB Audio dongle for sound.

This is a good idea. I did the same in my HemiMac and added a small internal amplifier. Works flawless.

MacTester
 
Status
Not open for further replies.
Back
Top