Mastodon Politics, Power, and Science

Wednesday, January 15, 2014

General formula for additive series

I couldn't sleep, so instead I figured out the formulas for a whole family of additive series. (x* n ^2 - (x-2)n )/2 where x is the amount you add each time, starting with one and n is the count of the series. This is a general solution to any fixed addition series counting from one. It was really amazing when I changed the program to work with the next entry in the series and it just worked.

https://github.com/BuckRogers1965/Examples/blob/master/Math/additiveSeries/additiveSeries.c

#include <stdio.h>


int main () {


  int i, j, n, x;

  for (x=1; x<20; x++) {
    printf("for additive series of size %d\n", x);
    for (i = 1, j = 0, n =1 ; n<10; n++, i+=x ){
      j+=i;
      printf("%d  %d  %d  %d \n", n, i, j, (x*n*n-(x-2)*n)/2);
    }
    printf("\n\n");
  }

}

Output:
for additive series of size 1

1  1  1  1 

2  2  3  3 

3  3  6  6 

4  4  10  10 

5  5  15  15 

6  6  21  21 

7  7  28  28 

8  8  36  36 

9  9  45  45 





for additive series of size 2

1  1  1  1 

2  3  4  4 

3  5  9  9 

4  7  16  16 

5  9  25  25 

6  11  36  36 

7  13  49  49 

8  15  64  64 

9  17  81  81 





for additive series of size 3

1  1  1  1 

2  4  5  5 

3  7  12  12 

4  10  22  22 

5  13  35  35 

6  16  51  51 

7  19  70  70 

8  22  92  92 

9  25  117  117 





for additive series of size 4

1  1  1  1 

2  5  6  6 

3  9  15  15 

4  13  28  28 

5  17  45  45 

6  21  66  66 

7  25  91  91 

8  29  120  120 

9  33  153  153 





for additive series of size 5

1  1  1  1 

2  6  7  7 

3  11  18  18 

4  16  34  34 

5  21  55  55 

6  26  81  81 

7  31  112  112 

8  36  148  148 

9  41  189  189 





for additive series of size 6

1  1  1  1 

2  7  8  8 

3  13  21  21 

4  19  40  40 

5  25  65  65 

6  31  96  96 

7  37  133  133 

8  43  176  176 

9  49  225  225 





for additive series of size 7

1  1  1  1 

2  8  9  9 

3  15  24  24 

4  22  46  46 

5  29  75  75 

6  36  111  111 

7  43  154  154 

8  50  204  204 

9  57  261  261 





for additive series of size 8

1  1  1  1 

2  9  10  10 

3  17  27  27 

4  25  52  52 

5  33  85  85 

6  41  126  126 

7  49  175  175 

8  57  232  232 

9  65  297  297 





for additive series of size 9

1  1  1  1 

2  10  11  11 

3  19  30  30 

4  28  58  58 

5  37  95  95 

6  46  141  141 

7  55  196  196 

8  64  260  260 

9  73  333  333 





for additive series of size 10

1  1  1  1 

2  11  12  12 

3  21  33  33 

4  31  64  64 

5  41  105  105 

6  51  156  156 

7  61  217  217 

8  71  288  288 

9  81  369  369 





for additive series of size 11

1  1  1  1 

2  12  13  13 

3  23  36  36 

4  34  70  70 

5  45  115  115 

6  56  171  171 

7  67  238  238 

8  78  316  316 

9  89  405  405 





for additive series of size 12

1  1  1  1 

2  13  14  14 

3  25  39  39 

4  37  76  76 

5  49  125  125 

6  61  186  186 

7  73  259  259 

8  85  344  344 

9  97  441  441 





for additive series of size 13

1  1  1  1 

2  14  15  15 

3  27  42  42 

4  40  82  82 

5  53  135  135 

6  66  201  201 

7  79  280  280 

8  92  372  372 

9  105  477  477 





for additive series of size 14

1  1  1  1 

2  15  16  16 

3  29  45  45 

4  43  88  88 

5  57  145  145 

6  71  216  216 

7  85  301  301 

8  99  400  400 

9  113  513  513 





for additive series of size 15

1  1  1  1 

2  16  17  17 

3  31  48  48 

4  46  94  94 

5  61  155  155 

6  76  231  231 

7  91  322  322 

8  106  428  428 

9  121  549  549 





for additive series of size 16

1  1  1  1 

2  17  18  18 

3  33  51  51 

4  49  100  100 

5  65  165  165 

6  81  246  246 

7  97  343  343 

8  113  456  456 

9  129  585  585 





for additive series of size 17

1  1  1  1 

2  18  19  19 

3  35  54  54 

4  52  106  106 

5  69  175  175 

6  86  261  261 

7  103  364  364 

8  120  484  484 

9  137  621  621 





for additive series of size 18

1  1  1  1 

2  19  20  20 

3  37  57  57 

4  55  112  112 

5  73  185  185 

6  91  276  276 

7  109  385  385 

8  127  512  512 

9  145  657  657 





for additive series of size 19

1  1  1  1 

2  20  21  21 

3  39  60  60 

4  58  118  118 

5  77  195  195 

6  96  291  291 

7  115  406  406 

8  134  540  540 

9  153  693  693 




Thursday, December 19, 2013

Created my first 3D printer design. An external RFID case.

I am planning on playing around with RFID to open the door to my house.  The RFID board I am using is just a circuit board, so I needed something to mount and protect it outside the door. I didn't see anything on Thingiverse, and I had just looked at an openscad tutorial, so I went through step by step and made an enclosure I thought would work for me.

Downloadable from here:

http://www.thingiverse.com/thing:207213


Building a framework to manage Hackmaster character sheet management

I'm working on a project with a friend to manage the Hackmaster RPG character sheets on the web.

We are working to set up a basic framework for the site.  We want a single page to be updated dynamically with no reloads at all.

Our thought is to use MongoDB using Perl on the web server back-end as the presistant data store.  Then use jquery to pass data to and from the server to the web page.  Finally Use knockoutjs to update the data elements in the page.

How to install mongodb on Ubuntu:  http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

How to install knockoutjs: http://knockoutjs.com/downloads/index.html

Testing if mongodb works:

> Mongo
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings:
Mon Sep  2 22:30:58.039 [initandlisten]
Mon Sep  2 22:30:58.039 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Mon Sep  2 22:30:58.040 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Mon Sep  2 22:30:58.040 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
Mon Sep  2 22:30:58.040 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Mon Sep  2 22:30:58.040 [initandlisten]
> db.test.save( { a: 1 } )
> db.test.find()
{ "_id" : ObjectId("52254b79b578d8dc54e545ac"), "a" : 1 }
> quit
function quit() { [native code] }
> quit()
Next thing I need to do is to write a little perl cgi script to act as a gateway between the web page and mongo. 

How to redesign the future.

One of the major problems in people's lives is that too much stuff we use is not designed to work together. The people who design the different systems in our houses (heaters, dishwashers, clothes washers, dryers, fridges, freezers), our cars, our phones, and our computers are all work independently, with no concept of managing the houses power.  This inefficiency in design makes the modern house nearly impossible to convert to alternative energy systems.

If I were running a huge high tech company,  I would take in 100 random families from every area in the country, 2 per state, and build them 10 different  styles of housing, ecologically sound and sustainable, something that reuses a lot things we think of us as waste today.  The initial building should be engineered to last 100 years. I would design these houses so that even if they were torn down, everything that went in them could be used again in another house.

The houses should each be independent, off the grid and not connected to any utilities. They should have sufficient solar panels and wind generators to power the house and to recharge the electrical vehicles and electric mowers, and electric power tools.

I would roll out 10 versions, to 10 families each, of a complete set of technologies, and create a single environment that spans from smart phones, to pad computers, to TVs, to laptops, to desktop machines. An environment that would make it impossible to lose data, that securely shared info anywhere in the world, proof even against the best intelligence agency/corporate spying.  That could scale up temporarily using shared cloud processors to inexpensively perform massive calculations in the blink of an eye.

This environment would span all the house systems, including the appliances, heating, cooling, and hot water generation.  By centrally managing when each system is drawing their highest amount of power so that they take turns you could reduce the maximum amount of amps needed to run a home by a factor of 10.  Just by taking turns, not running the the washer up in a spin cycle when the freezer compressor is running, you can massively reduce the maximum level of required amps. By using LED lighting, and light pipes to bring in ambient sunlight you could reduce the power required for lighting to about 1/4 of that required for florescent lights. Half the energy used in a house goes to heating water. By using solar water heaters you could make the cost of generating hot water essentially free.

Such a house could easily be powered by a many fewer solar panels and a much smaller set of lead acid batteries than a standard house that does not intelligently manage its power requirements.  This makes the return on investment of the solar and wind power generation system pay back in just a few years instead of in decades.

I would combine the best features and requests of all these different groups of people, fix any problems they run into, and finally roll out a complete solution to living, that uses tech as a tool to make people's lives better and more complete.  The reuse and recycling of common waste items would create entire new sectors of our economy. I would radically redesign everything from scratch, creating a house that can be build and maintained for much less than anything mass produced today.

Finally I would redo how houses are built. I would manage the way houses are build centrally, for economies of scale. Think car manufacture, not house contractor for the model I would use to roll out these new methods of living. But the houses would be designed online by the customer, then the blueprints generated would be approved by an engineer and an architect, working with the customer to quickly nail down any issues, any custom construction built in a large building and shipped to the customer site where a uniformed professional work crew that makes a living wage would assemble the homes.

Thursday, August 1, 2013

Today's Sensor is the Joy Stick!

I am slowly going through all 37 of the modules in the Sunfounder lab kit, one a day. 

Tonight I wired up the joystick, and tried out the sketch from the documentation.  The markings on the board were good, and with the help of the sketch I was quickly reading the analog values, but the digital button seemed to not work.  I remembered that there is a built in 20K ohm resistor inside the Arduino.  This means that the pin will normally be high, and then go low when you press the button.



Save this file as Joystick.ino inside a Joystick directory in your Arduino folder.
int jX = 0; // Analog pins for X and Y axis.
int jY = 1;
int jZ = 7; // Digital pin on Z axis.

void setup ()
{
  pinMode (jX, INPUT);
  pinMode (jY, INPUT);
  pinMode (jZ, INPUT);
  digitalWrite(jZ, HIGH);  // This was missing.
  // The above line sets the pin high
  // and engages an internal resistor.
  Serial.begin (9600);
}

void loop ()
{
  int x, y, z;
  static int px, py, pz;
  x = analogRead (jX) / 10.24 - 50;
  y = analogRead (jY) / 10.24 - 50;
  z = digitalRead (jZ) ;
 
  if ( px!=x || py!=y || pz!=z ){
    Serial.print (x, DEC);
    Serial.print (",");
    Serial.print (y, DEC);
    Serial.print (",");
    Serial.println (z, DEC);
  
    px=x;
    py=y;
    pz=z;
  }
 
  delay (200);
}



I added in some logic to only report when there is a change, the static keyword only allocates the variables once, and then stores the old value. I also scaled the range from 0 to 99 on the x and y axis, and then subtracted 50 so that center scale is zero.

The pin out markings were good on this one.

Wednesday, July 31, 2013

37 sensor kit from Sunfounder lab

So, I saw this kit on Amazon.  It seemed too good too be true.  The kit was priced right, it was less than 2 dollars for each board.  Of course many of the boards are not sensors, some of the 37 are emitters of various frequencies of light and sound.

The package arrived in just a few days.  It was small enough to have been left by my mail carrier in my mail box.  I opened the medium sized padded envelope  and pulled out a nice plastic case that firmly latched shut.  Opening the case revealed the 37 modules each in little plastic bags.  None of them were labelled and there was no documentation.  Each module seemed to be well made and I didn't see any badly soldiered joints. 

Freshly unpacked.


Everything came mounted on tiny boards.  These easily plugged into a breadboard and I was able to connect several different modules to an Arduino board.   I sorted the various modules 2 or three into a single small bag.  I used the picture from the Amazon web page to identify each item.  This got rid of more than half the bags and organized the modules by function.

The list of modules from Amazon:

1.Passive Buzzer Module
2.common-cathode RED&GREEN LED Module
3.Knock sensor module
4.Shock-switch sensor Module
5.Photo resistor sensor Module
6.Push button Module
7.tilt-switch Module
8.RGB LED Module
9.infrared-transmit Module
10.RGB LED Module
11.hydrargyrum-switch sensor Module
12.two-color commoncathode LED Module
13.Active buzzer Module
14.Analog-temperature sensor Module
15.Colorful Auto-flash Module
16.Magnet-ring sensor Module
17.Hall sensor Module
18.Infrared-receive sensor Module
19.Analogy-Hall sensor Module
20.Magic-ring Module
21.Rotate-encode Module
22.Light break sensor Module
23.Finger-Pulse sensor Module
24.Magnetic spring Module
25.Obstacle avoidance sensor Module
26.Tracking sensor Module
27.Microphone sensor Module
28.Laser-transmit Module
29.Relay Module
30.18b20 temperature sensor Module
31.Digital-Temperature sensor Module
32.Linear-Hall Sensor Module
33.Flame sensor Module
34.High-sensitive voice sensor Module
35.Humidity sensor Module
36.Joystick PS2 Module
37.touch sensor Module


There was also a download link that had more information about how to use the various modules. 

The download is kind of a mess.  The manual reads like it was machine translated from another language.  I need to work on cleaning this up and uploading it to github so that people can just drop in the library and have examples for all the modules, and modules that show how to wire everything up.

It was also not clear to me how to wire these modules up to an Arduino board.


Oh look, it is a DHT11 !  Ignore the G N D V, that is just gibberish.


Looking down from the top, brown wire is ground, red is 3.3-5v power, and orange is signal.


Conclusion

Overall the hardware is nice.  Everything I have spent the time figuring out I have been able to get working.  Many of these boards would be several dollars individually by themselves.  The humidity sensor itself is 5 or 6 dollars if bought by itself.  IR receiver's are $2 as a bare component.  Having the bare component mounted on small boards makes it much easier to breadboard up examples, and the components are much tougher mounted in the modules than they would be otherwise.  Especially for me, since as I get older my hands get more and more apelike.

The only possible thing that one might consider bad is that many of these boards are near duplicates... there are 4 modules that sense temperature, 3 hall effect modules, a couple RGB lights, and so on. A little less duplication and a little more variety might be good.  But this might also be seen by some as a good thing.  Maybe you want to explore how variations on these components all work. 

Unfortunately, if you are currently looking for something you can just buy and get working in a day, you must look elsewhere.  The sole negative, but it is a giant negative, is that the Arduino sketches and instructions on how to wire up these modules is fairly difficult to do.  I've been spending a couple of hours getting each sensor to work in an evening.  I like doing this, so no big deal to me, but this might be a deal breaker for someone else.

Another thing that would be nice would be to throw in a few 3 wire, 4 wire, and one 5 wire female to male connectors so that you can easily wire the components right up to the pins on an Arduino board.  I bought this wiring kit for the variety of wiring options it gave me for Arduino, breadboard, and Raspi.

Thursday, July 18, 2013

Update on my Raspbmc media player project.

The Infrared Remote control is working great now.  This means that I can just reuse a free old remote control and move the $20 wireless USB keyboard onto another project.    This also means that the player draws even less power now, the IR Receivers are amazingly low power.  I am re-using the old remote control from the media player that Netgear deactivated as soon as I hooked it up to the Internet. 

I got an IR receiver from Lady Ada's site here:  http://www.adafruit.com/products/157 for just a couple of dollars.  Plus shipping, so buy a lot of other stuff there too. *L*

I also bought the cable and bread board connector for the Raspi here:  http://www.adafruit.com/products/914 Since this is  reusable for many projects I consider it a tool and am not adding it to the cost of this single project.

If you want they sell a remote control with a configuration file all figured out for you already.  If you want to reuse and old remote, that is easy to do too.

I followed the directions on Ada Fruit as well and programmed my remote control in just a few minutes.

http://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center

I had to type in the commands from a screen shot, here is something you can copy and paste from:

sudo modprobe lirc_rpi
sudo kill $(pidof lircd)

mode2 -d /dev/lirc0
irrecord -d /dev/lirc0 ~/lircd.conf
 

A lot of remote controls have been programmed already, and the config files shared at this site: http://lirc.sourceforge.net/remotes/

This receiver is so much more sensitive than any I have ever used before.  I can literally point the remote control 180 degrees away from the chip and it still reads the button presses.  The old media player would sometimes not get a button press pointing right at it.

I have three more of the chips and 3 more Raspi boards, so I will be adding a wire harness to each of these 4 chips and wiring up every Raspi I own with inexpensive IR. 

The Raspi's can also send IR so I will be working on that next. 

Player Portal in Mega Mappers

Codex Engine: Player Portal, Auth, Rules-as-MCP & AI NPCs (Pure Node-Tree Edition) Defining game rulesets (D&D 5e, Pathfinder, Cyber...